Hi All,
I have been playing with the PSWindowsUpdate module and have come out with the below script. It works well and sends me an emails with the an attached copy of updates available on each server. However, it seems that if one of the servers doesn’t require any updates, the HTML report comes back blank. Does anyone have any ideas on this?
` $Subject = “Server Updates as of $(Get-Date)”
$Attachment = “C:\Powershell\ServerUpdates\AvailableUpdates.htm”
$Body = “Please see attached the latest Server updates”
Measure how long it takes to run the script
$StartDTM = (get-date)
Import the Update Module
ipmo ‘\ServerShare\SCRIPTS$\PSWindowsUpdate’
$Servers = (Get-Content “C:\Powershell\ServerUpdates\test.txt”)
#embed a stylesheet in the html header
$head = @"
body { background-color:#dddddd;
font-family:Tahoma;
font-size:12pt; }
td, th { border:1px solid black;
border-collapse:collapse; }
th { color:white;
background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px }
table { margin-left:50px; }
"@
$Fragment = " Required Server Updates $(Get-Date) "
$Updates = Get-WUList -ComputerName $Servers
group data by KB Number
$Groups=$Updates | Group-Object -Property KB
Check Updates for each server
ForEach ($Update in $Groups) {
$Fragment+=“$($Update.name)”
define a collection of Updates from the group object
$KB=$Update.group
create an html fragment
$Fragment += $KB | Select-Object -Property ComputerName,KB,Status,Title,Size | ConvertTo-HTML -Fragment -As Table | Out-String
}
$EndDTM = (Get-Date)
$Footer=(“Elapsed Time: $(($endDTM-$startDTM).totalseconds) seconds”)
$Fragment+=$Footer
ConvertTo-Html -head $head -body $Fragment | Out-File C:\Powershell\ServerUpdates\AvailableUpdates.htm
Send-MailMessage -SmtpServer ServerFQDN -From service@domain.com -Subject $Subject -To user@domain.com -Attachments $Attachment -Body $Body -BodyAsHtml
`