我正在尝试加入两个格式化的信息列表:
Get-WmiObject -class Win32_OperatingSystem | Format-List Caption
Get-WmiObject -class Win32_Processor | Format-wide Name,Manufacturer,MaxClockSpeed
当我使用这两个命令时,我得到以下输出(包括空格):
Caption : Microsoft Windows 8 Pro
Name : Intel(R) Core(TM) i7-2670QM CPU @ 2.20GHz
Manufacturer : GenuineIntel
MaxClockSpeed : 2201
有没有简单的方法来连接这两个列表,从而减少空格并在冒号和字符串之间获得相同的间距?
答案 0 :(得分:3)
根据从每个wmi类中选择的属性创建一个新对象:
$os = Get-WmiObject -class Win32_OperatingSystem | Select-Object Caption
$processor = Get-WmiObject -class Win32_Processor | Select-Object Name,Manufacturer,MaxClockSpeed
New-Object PSObject -Property @{
Caption = $os.Caption
ProcessorName = $processor.Name
ProcessorManufacturer = $processor.Manufacturer
ProcessorMaxClockSpeed = $processor.MaxClockSpeed
}