troubleshooting Question

Powershell - why could this line be failing to run on some servers

Avatar of String :-)
String :-)Flag for Australia asked on
2 Comments1 Solution124 ViewsLast Modified:
I am trying to audit the number of pending updates for each server using Get-PendingUpdates found in the gallery, but this script fails to run on a some of our 2016 servers.

(script below)

Problematic servers pause indefinately whilst running the following line
$SearchResult = $UpdateSearcher.Search("IsAssigned=1 and IsHidden=0 and IsInstalled=0")

Most servers run the query OK in 2-3 seconds, however some of our servers pause on is this line indefinitely:

Other key points:
Same problem using PSSession AND\OR locally using Powershell (running as admin).
Powershell.exe in taskmanager CPU% is 0. Private working memory 26,748 (doesnt move)

Our servers are all deployed from the same Server 2016 template so it doesnt make sense to me why some would be OK and others not.

Can anyone offer any troubleshooting tips?. Possible causes.  Rebooting servers is not really an option at the moment.

#Get All Assigned updates in $SearchResult
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
$SearchResult = $UpdateSearcher.Search("IsAssigned=1 and IsHidden=0 and IsInstalled=0")
#Matrix Results for type of updates that are needed
$Critical = $SearchResult.updates | where { $_.MsrcSeverity -eq "Critical" }
$important = $SearchResult.updates | where { $_.MsrcSeverity -eq "Important" }
$other = $SearchResult.updates | where { $_.MsrcSeverity -eq $null }

#Write Results
Write-Host "total=$($SearchResult.updates.count)"
Write-Host "critical=$($Critical.count)"
Write-Host "important=$($Important.count)"
Write-Host "other=$($other.count)"
System Engineer | .NET Developer | Microsoft MVP | Technical Speaker

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros