收集有关多台计算机的特定图像和硬件信息

时间:2017-02-07 17:37:41

标签: powershell wmi

我想要做的是从我公司的100多个资产中收集大量资产的具体信息。

文本文件只是计算机主机名列表

desktop12345
desktop23456
etc.

这是我到目前为止所拥有的:

$assets = Import-Csv 'c:\users\xxxxx\desktop\tex docs\assets.txt'

foreach ($asset in $assets) {
  Get-CimInstance Win32_OperatingSystem |
    Select-Object CSname, OSArchitecture, version, BuildNumber, OSType, InstallDate,
                  operatingsystemsku, ServicePackMajorVersion, encryptionlevel | FL
}

但即使我有一个列表,它只会返回有关我的资产的信息。我认为我需要在第一部分中替换Get-WmiObject -Class Win32_Desktop -ComputerName,但不是100%确定我应该如何格式化它。

也许是这样的:

$assets = Import-Csv 'c:\users\xxxxx\desktop\tex docs\assets.txt'

foreach ($asset in $assets) {
  Get-WmiObject -Class Win32_OperatingSystem -ComputerName |
    Select-Object CSname, OSArchitecture, version, BuildNumber, OSType, InstallDate,
                  operatingsystemsku, ServicePackMajorVersion, encryptionlevel | FL
}

1 个答案:

答案 0 :(得分:2)

这是猜测,取决于文本文件的格式,假设它是直接的计算机列表。如果它不仅仅是一个列表,请编辑问题以显示文件的样子。

$assets = Get-Content 'c:\users\xxxxx\desktop\tex docs\assets.txt'

$output = foreach ($asset in $assets) {
     Get-WmiObject -class Win32_operatingSystem -ComputerName $asset | 
         Select-Object  CSname, OSArchitecture, version, BuildNumber, OSType, InstallDate, operatingsystemsku, ServicePackMajorVersion, encryptionlevel
}
$output | fl

编辑:

根据Ansgar Wiechers的建议简化

$assets = Get-Content 'c:\users\xxxxx\desktop\tex docs\assets.txt' 
Get-WmiObject -class Win32_operatingSystem -ComputerName $assets | 
    Select-Object  CSname, OSArchitecture, version, BuildNumber, OSType, InstallDate, operatingsystemsku, ServicePackMajorVersion, encryptionlevel |
    fl