Friday, 29 September 2017

powershell - How to check if windows has automatic updates waiting from the command line?


If a Windows server (2k3/2k8) is set to "download but not install" updates, is there a way to check from the command line.. perhaps a log file or something I can check with powershell, to see if there are any updates actually waiting to be installed? I'm trying to prevent having to manually log on to each server to check, even though they want the "trigger" pulled manually. We have an automation system in place I can use (CA Autosys) - just not sure what to have it look for.



Answer



We can use IUpdateSearcher::Search to determine the number of yet to be installed updates:


$session = New-Object -com "Microsoft.Update.Session"

$searcher = $objSession.CreateUpdateSearcher()

$results = $objSearcher.search("IsInstalled=0")

$results.updates.count

If you need to do installation by another script, assign the above variables first and add:


$installer = New-Object -com "Microsoft.Update.Installer"

$installer.Updates = $results.updates

foreach ($update in $objresults)
{
$objInstaller.install()
}

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...