$server = Get-Content C:\Users\SCCM_admin\Desktop\servers.txt
foreach ($ser in $server){
Write-Host "Getting info for server $ser" -ForegroundColor Green
Invoke-Command -ComputerName $ser -ScriptBlock {
$updateInfoMsg = "Windows Update Status: `n";
$UpdateSession = New-Object -ComObject Microsoft.Update.Session;
$UpdateSearcher = $UpdateSession.CreateupdateSearcher();
$Updates = @($UpdateSearcher.Search("IsAssigned=1 and IsHidden=0 and IsInstalled=0 and Type='Software'").Updates);
$Found = ($Updates | Select-Object -Expand Title);
$WindowsUpdateInfo = New-Object -ComObject Microsoft.Update.AutoUpdate;
$lastchecked = $WindowsUpdateInfo.Results;
#$WindowsUpdateInfo.Results
If ($Found -eq $Null) {
$updateInfoMsg += "Up to Date";
Write-host "Last checked:" ($WindowsUpdateInfo.Results).LastSearchSuccessDate -ForegroundColor Cyan
} Else {
Write-host "Last checked:" ($WindowsUpdateInfo.Results).LastSearchSuccessDate -ForegroundColor Cyan
$Found = ($Updates | Select-Object -Expand Title) -Join "`n";
$updateInfoMsg += "Updates available:`n";
$updateInfoMsg += $Found;
}
Return $updateInfoMsg, "`n";
Write-Host $updateInfoMsg
}
}
No comments:
Post a Comment