【发布时间】:2021-06-03 09:31:11
【问题描述】:
示例代码::-
$hash = $null
$hash = @{}
1..8 | ForEach-Object {
if (Test-Connection -ComputerName "192.168.1.$_" -Count 1 -Quiet -ErrorAction "SilentlyContinue") {
try{
$proc = Get-WmiObject -Class Win32_operatingsystem -ComputerName "192.168.1.$_" -ErrorAction Stop |
select CSName,caption
foreach ($p in $proc)
{
$hash.add($p.csname,$p.caption)
}
}
catch{
write-warning "Unable to get WMI info from '192.168.1.$_'" |
out-file "results.txt" -append
}
}
else {
write-warning "Unable to connect to '192.168.1.$_'" |
out-file "results.txt" -append
}
}
$hash
结果::
Name Value
---- -----
DC Microsoft Windows Server 2016 Standard
SCCMCB Microsoft Windows Server 2016 Standard
WIN1020H2 Microsoft Windows 10 Enterprise Evaluation
DESIRED Result 也应包含“IP”::
Name IP Value
---- -----
DC 192.168.1.3 Microsoft Windows Server 2016 Standard
SCCMCB 192.168.1.5 Microsoft Windows Server 2016 Standard
WIN1020H2 192.168.1.7 Microsoft Windows 10 Enterprise Evaluation
【问题讨论】:
标签: powershell