从 PowerShell 3 开始,PSCustomObject
可以将从其他地方收集的有用信息方便地合并进来。以下例子从不同的 WMI 类获取各种信息,并且输出为一个清单。该清单可以传递给其它命令,也可以直接使用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| $Computername = "."
$comp = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Computername $bios = Get-WmiObject -Class Win32_bios -ComputerName $Computername $os = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computername
[PSCustomObject]@{ ComputerName = $Computername Timestamp = (Get-Date -Format 'yyyy-MM-dd HH:mm:ss') Model = $comp.Model Manufacturer = $comp.Manufacturer BIOSVersion = $bios.SMbiosbiosversion BIOSSerialNumber = $bios.serialnumber OSVersion = $os.Version InstallDate = $os.ConvertToDateTime( $os.InstallDate) LastBoot = $os.ConvertToDateTime($os.lastbootuptime) LoggedOnUser = $Comp.UserName }
|