I have been using the module "PSWindowsUpdate" to automate updates on our client machines at specific times, however, now I have been asked to also have a report on which updates are available and about to be installed, emailed to our admin team.
(While I have been using PSWindowsUpdate for this, I am happy to use something else)
I am struggling to make it give me a useable output.
For example:
$WUList = Get-WUList
Send-MailMessage -to $To -from $From -Subject $Subject -smtpserver $SMTPServer -Credential $SMTPCreds -Body $WUList
Gives me this error:
Send-MailMessage : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Body'. Specified method is not supported.
Send-MailMessage -to $To -from $From -Subject $Subject -smtpserver $SMTPServer -Credential $SMTPCreds -Body ($WUList | Out-String)
Almost works, and I get this in my email body:
ComputerName Status KB Size Title
------------ ------ -- ---- -----
DESKTOP-L... ------ KB4023307 13 MB Microsoft Silverlight (KB4023307)
DESKTOP-L... D----- KB4088776 182 GB 2018-03 Cumulative Update for Windows 10 Version 1709 for x64-based Systems (KB4088776)
But that is all, and not particularly well formatted.
$MessageContent = "
Updates are available.
These updates will be installed:
$WUList
"
Send-MailMessage -to $To -from $From -Subject $Subject -smtpserver $SMTPServer -Credential $SMTPCreds -Body $MessageContent
Send-MailMessage -to $To -from $From -Subject $Subject -smtpserver $SMTPServer -Credential $SMTPCreds -Body ($MessageContent|Out-String)
Are close, but the message body contains:
Updates are available.
These updates will be installed:
System.__ComObject System.__ComObject
So, in conclusion, has anyone found a way of formatting the output of Get-WUList so it can be used?
I have tried playing around with changing the Type, and converting from System.Object, but without any luck.
(I have also asked on the PowerShell Gallery page for this module, but this forum is much more active)