【发布时间】:2018-03-06 09:41:51
【问题描述】:
我将(使用 PowerShell 脚本)创建一个表并将结果(正/负)添加到其中。 我有一个文本文件computers.txt,其中列出了所有PC。
这样
CSNAME 修补程序信息 PC1 已安装 PC2 未安装 PC3 已安装 等等。使用我的实际脚本,我只能看到积极的结果。
Get-Content .\computers.txt | Where {
$_ -and (Test-Connection $_ -Quiet)
} | foreach {
Get-Hotfix -Id KB4012212 -ComputerName $_ |
Select CSName,HotFixID |
ConvertTo-Csv |
Out-File "C:\$_.csv"
}
【问题讨论】:
-
你用
(Test-Connection $_ -Quiet)过滤掉 一些 不好的结果,其余的用Get-Hotfix -id KB4012212 -computername $_过滤,因为空值不会被传递到 pipt 。如果您想查看更多信息,您需要为每台计算机运行这些命令并保存结果。检查结果,它们没有任何你可以传递空对象或类似 [pscustomobject]@{CSName=$_;HotFixID="N/A"} -
您的
computers.txt是TSV文件?
标签: powershell if-statement hotfix