0

我将(使用 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"
}
4

1 回答 1

0

我建议解析和处理正负结果(也比管道更快ForEach-Object):

:parse ForEach ($Computer in (Get-Content C:\Path\computers.txt))
{
    If (Test-Connection $Computer -Quiet)
    {
        $Result = Get-Hotfix -Id KB4012212 -ComputerName $Computer -ErrorAction 'SilentlyContinue'

        If ($Result)
        {
            $Result |
              Select-Object -Property CSName,HotFixID |
              ConvertTo-Csv -NoTypeInformation |
              Out-File "C:\$Computer.csv"
            Continue :parse
         }
         "`"CSName`",`"HotFixID`"`r`n`"$Computer`",`"NUL`"" |
           Out-File "C:\$Computer.csv"
    } Else { Write-Host 'Unable to connect to $Computer' }
}
于 2017-09-25T15:26:29.077 回答