KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

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

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Library
View previous topic :: View next topic  
Author Message
Kris



Joined: 12 May 2010
Posts: 375

PostPosted: Fri Nov 27, 2020 5:17 am    Post subject: PS: Days Since Last Windows Update (W2K12R2 and up) Reply with quote

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:
powershell.exe %script% %params%


Powershell script:
Code:
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!
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12790
Location: USA

PostPosted: Fri Nov 27, 2020 6:03 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Kris



Joined: 12 May 2010
Posts: 375

PostPosted: Fri Nov 27, 2020 6:34 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12790
Location: USA

PostPosted: Fri Nov 27, 2020 6:47 am    Post subject: Reply with quote

Yeah, somehow Windows WMI classes miss some updates

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
oakyuz



Joined: 08 Feb 2007
Posts: 74

PostPosted: Sun Nov 29, 2020 6:59 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Kris



Joined: 12 May 2010
Posts: 375

PostPosted: Mon Nov 30, 2020 3:32 am    Post subject: Reply with quote

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....
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index