Home > Blockchain >  How can I check how long ago the last windows update has been installed with a powershell script?
How can I check how long ago the last windows update has been installed with a powershell script?

Time:11-15

I'm looking to write a powershell script that checks the date the last windows update has been installed on the client, check if it has been over a week (the script is to be run monthly, a week after patchday), and if it has, an email is to be sent to the user telling them to connect to the WSUS Server ASAP to get the newest updates. I have very limited experience using powershell so if anyone here has some input it would be greatly appreciated.

CodePudding user response:

The following code should work:

$lastupdate = (get-wmiobject -class win32_quickfixengineering).installedon | Sort-Object -Property installedon -Descending
$Date = Get-Date

$diff = New-TimeSpan -Start $lastupdate[0] -end $Date
if ($diff.days -ge 7) {

#Script to send email goes here

}

Note: This needs to be run as administrator.

  • Related