Hello,
I've attempted to modify the script located at:
http://www.microsoft.com/technet/scr....mspx?mfr=true
It lists the computers neededing a restart after updates have been installed
(we currently have configured to not restart if a user is logged on via GPO).
My modification to send the info via email works fine if run manually but if
run as a scheduled task the email is not sent. I have other powershell
scripts that run fine as scheduled tasks but I am at a loss on this one. Any
assistance is appreciated. Bill
The line "If ($all -eq $null)" is set for testing. Currently there are no
computers that need restarting so the -eq $null sends the email, just with no
computers listed (well, it does if run manually anyway)
The script:
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null
if (!$wsus) {
$wsus =
[Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
}
$computerScope = new-object
Microsoft.UpdateServices.Administration.ComputerTargetScope;
$computerScope.IncludedInstallationStates =
[Microsoft.UpdateServices.Administration.UpdateInstallationStates]::InstalledPendingReboot;
$updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope;
$updateScope.IncludedInstallationStates =
[Microsoft.UpdateServices.Administration.UpdateInstallationStates]::InstalledPendingReboot;
$computers = $wsus.GetComputerTargets($computerScope);
$all = $computers | foreach-object {
$_.FullDomainName | Out-Null;
}
If ($all -eq $null) {
$emailFrom = "WSUS@xxxxxx"
$emailTo = "user@xxxxxx"
$subject = "Server Restart Required"
$bText1 = "The below server(s) have received Windows Updates and are in need
of a restart:" + "`r`n"
$bText2 = "`r`n" + $all + "`r`n"
$bText3 = "The server(s) most likely have a user logged on." + "`r"
$bText4 = "WSUS is configured to NOT restart a server if a user is logged on
`r`n"
$body = $bText1 + $bText2 + $bText3 + $bText4
$smtpServer = "SMTPSERVER"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
}


).