Servers pending reboots via WSUS and email

We have been working on a WSUS project , and its coming to a close. The client required information on which servers required rebooting to complete a patch.

We came up with this script

 

$csvfile=’drive WSUS Scriptsrebootpending.csv’
Try{
[void][reflection.assembly]::LoadWithPartialName(‘Microsoft.UpdateServices.Administration’)
$wsus=[Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer()
$computerScope = new-object Microsoft.UpdateServices.Administration.ComputerTargetScope
$computerScope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::InstalledPendingReboot
$wsus.GetComputerTargets($computerScope) |
Select FullDomainName,IPAddress,RequestedTargetGroupName |
Export-Csv $csvfile -NoType

}
catch{
throw
}

$smtpServer = “your smtp server”
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($csvfile)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = “your address”
$msg.To.Add(“your address”)
$msg.Subject = “pending reboots”
$msg.Body = “Check attachment:”,$messagebody
#”Here is todays copy for ”
$msg.Attachments.Add($att)
$smtp.Send($msg)
#$att.Dispose()

Leave a Reply

Your email address will not be published. Required fields are marked *