0
如何將我的腳本的結果放在具有良好格式的同一頁上?當前if
和else
被輸出到控制檯和Out-GridView
。如何在IF Else的同一頁上輸出結果?
$PCList = "C:\Scripts\Get-ADComputers\Win7.txt"
foreach ($PC in Get-Content $PCList) {
if (-not(Test-Connection -ComputerName $pc -BufferSize 16 -Count 2 -Quiet)) {
Write-Host "$pc is not reachable" -ForegroundColor "yellow"
} else {
Invoke-Command -ComputerName $pc -ScriptBlock {
$Session = New-Object -ComObject "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(0, $historyCount) |
Where-Object {$_.title -like "*KB4019264*"} |
Select-Object Date,
@{name="Operation"; expression={switch($_.operation){1 {"Installation"}; 2 {"Uninstallation"}; 3 {"Other"}}}},
@{name="Status"; expression={switch($_.resultcode){1 {"In Progress"}; 2 {"Succeeded"}; 3 {"Succeeded With Errors"}; 4 {"Failed"}; 5 {"Aborted"}}}},
Title
} | Out-GridView
}
}
我有超過200名在'$ pclist',之後我運行你的建議的腳本,它只返回我身邊60的結果,包括「平能」和「未平,能夠」主人,爲什麼它'$ pclist'中的主機其餘部分缺少結果? –
很可能這些主機的歷史記錄中沒有修復程序KB4019264。如果您希望它們顯示爲「未安裝」,則需要檢查管道是否返回了結果並以其他方式創建自定義對象。 –