I'm working on a PowerShell script to check for pending updates in SCCM on about 150 servers. My goal is to identify updates that are stuck with an evaluation state other than 8, so I can take action to resolve those issues. Currently, I'm using a script that queries the local servers via WMI, but I'm having trouble filtering the resulting array to show only the updates I need to focus on. Specifically, I want to know why my filter `$jobs | ? {$_.evaluationstate -ne 8}` isn't working. I've also tried inspecting the properties with `$jobs | select evaluationstate`, but no luck there either. Any ideas on how I can successfully filter this array?
4 Answers
You're also right that using `Get-WmiObject` is getting a bit old. Consider switching to `Get-CIMInstance`, which is more efficient and recommended for the latest PowerShell versions. Plus, to speed up your script, you might run `Invoke-Command` with multiple computer names at once instead of one at a time in a loop—it'll save you a ton of time!
The issue stems from you piping the output through a `Format-*` command, like `ft`, which converts objects to a formatted view rather than keeping them as objects. Instead, you should modify your line to remove the `| ft`, so it reads `$jobs = @(get-job | Receive-Job | sort pscomputername)` without any formatting done to it. This way, you'll keep the objects intact and be able to filter them properly!
If you're still having trouble, consider using `Out-GridView` to interactively filter the results. You can have it pop up a window and select the data you care about, which might give you a clearer view to work from. It's useful for that 'hands-on' filtering approach if you're unsure about scripting it out just yet!
That sounds like a great idea! I'll give it a try.
Remember that when you're trying to filter your updates, using `Get-Member` can help you see what properties your `$jobs` array actually contains. If you're not seeing the `evaluationstate` property, there might be an issue with how the data is structured after your previous commands. This tool is really helpful to ensure you're working with the expected types!
Thank you so much! That fixed it.