I have tried several methods for gathering service data and I can't seem to get one to meet all my needs. Get-Service
works fine but is very slow when I pipe in a couple Where-Object
properties. Get-CimInstance
is much faster but I can't figure out how to exclude services. Any ideas?
Here's my code attempts so far. This one is fast until I add the Where-Object
. Then it takes 3 times longer if I do:
Get-Service -DisplayName * -ComputerName $Name -Exclude $ExcludedServices | Where-Object { $_.status -eq 'Running' -or $_.StartType -eq 'Automatic' }
This one works much faster but I don't know how to exclude a list of Services if needed:
Get-CimInstance -ClassName Win32_Service -ComputerName $Name | Where-Object { $_.state -eq 'Running' -or $_.StartMode -eq 'Auto' }
I don't know how to exclude a list of Services if needed
Get-CimInstance
allows you to impose a WQL WHERE clause constraint on the query:
Get-CimInstance Win32_Service -Filter 'Name != "excludedSvc"'
You can also restrict the items based on the State
or StartMode
properties inside the query, so the remote computer doesn't have to send back all of the services:
Get-CimInstance Win32_Service -Filter 'Name != "excludedSvc" AND State = "Running" AND StartMode = "Auto"'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With