PS: Days Since Last Windows Update (W2K12R2 and up)

If you have information, script, utility, or idea that can be useful for HostMonitor community, you welcome to share information in this forum.
Post Reply
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

PS: Days Since Last Windows Update (W2K12R2 and up)

Post by Kris »

This PowerShell test returns the days since last updates have been installed.
It takes the Windows machine name as parameter.
Works for me on W2K12R2 and up, as well as Windows 10.

Start cmd:

Code: Select all

powershell.exe %script% %params%
Powershell script:

Code: Select all

If (!$args[0])
    {
    echo  ScriptRes:Unknown:"No ComputerName specified"
    exit
    }


$ComputerName  = $args[0]
$Today         = (GET-DATE)
$UpdateDate    = Invoke-Command -ComputerName $ComputerName -ScriptBlock { ((get-hotfix).properties | where {$_.name -eq "installedon"}).value | select -last 1 }
If($UpdateDate) 
    {
    $DaysSince = (New-TimeSpan -Start $UpdateDate -End $Today).Days
    echo ScriptRes:Ok:$DaysSince
    }
Else
    {
    echo ScriptRes:Unknown:0
    }
No beauty, customize to your own requirements...

Happy Monitoring and Stay Safe!
KS-Soft
Posts: 12921
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Thank you.
But now HostMonitor offers built-in test method for such check (version 12.56).
Also version 12.60 will check for "reboot pending" flags (should be available next week).

Regards
Alex
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Post by Kris »

Hi Alex,
KS-Soft wrote:But now HostMonitor offers built-in test method for such check (version 12.56).
Also version 12.60 will check for "reboot pending" flags (should be available next week).
Of course, I am very aware of that.
However, I find the built-in test not quite accurate enough.
At this moment, I have a server that says 40 days with the built-in test, 20 days with my PS test.
When I look at the actual Windows update history, it is in fact 20 days....

So for now I will have to stick with my own code :wink:
KS-Soft
Posts: 12921
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Yeah, somehow Windows WMI classes miss some updates

Regards
Alex
oakyuz
Posts: 74
Joined: Thu Feb 08, 2007 5:48 am

Post by oakyuz »

Hi Kris

How do you handle the credential if HM or RMA does not have access permission for the checked system? As I see, you don't pass the credential info to the script and using the connection manager is not an option for this situation to pass the credential.

I had used a similar script before Windows Update test was implemented. However, due to credential problem, I could only check the systems that HM or RMA service account has access right. Because I did not want the credential info to pass to or embed into the script, other systems were left unchecked.

On the other hand, I suspected some unexpected result for this test similar to yours. However, I have not examined yet.

Regards
OÄŸuzhan
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Post by Kris »

Hi OÄŸuzhan,
oakyuz wrote:How do you handle the credential if HM or RMA does not
have access permission for the checked system?
That is an issue indeed.
I kinda solved it by passing the credentials Base64 encoded en decode it back in the script itself.
Which I know is quite easy to decipher, but still better than nothing.
For my scenario it was acceptable, I can imagine it will not be in many other cases....
Post Reply