Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Get-Service (Stop) but NOT display status "waiting for <x> service to stop..."

Basically, I don't have an issue with the action being taken. My question is about the status output of the action "waiting for..." message. Is there a way to suppress that message?

Example:

PS C:\Users\a.real.person.maybe> Get-Service *fewserviceswithmatchingprefixes* | Where-Object {$_.Name -notmatch 'somethinghere' -and $_.Name -ne 'alsosomethinghere' -and $_.Name -ne 'somethinghereprobably'} | Stop-Service
WARNING: Waiting for service 'thoseservicesabove' to stop...
WARNING: Waiting for service 'anotheroneofthoseservicesabove' to stop...

enter image description here

like image 578
Kazic Avatar asked Oct 25 '25 08:10

Kazic


2 Answers

You can either set the value of the $WarningActionPreference variable at the callsite to Ignore or SilentlyContinue (both will suppress consumption and rendering of the warning message):

$WarningActionPreference = 'SilentlyContinue'
Get-Service *fewserviceswithmatchingprefixes* | Where-Object {$_.Name -notmatch 'somethinghere' -and $_.Name -ne 'alsosomethinghere' -and $_.Name -ne 'somethinghereprobably'} | Stop-Service

Or you can use the -WarningAction common parameter explicitly when making the call to Stop-Service (it will only affect that particular invocation of Stop-Service):

... | Stop-Service -WarningAction SilentlyContinue
like image 60
Mathias R. Jessen Avatar answered Oct 26 '25 22:10

Mathias R. Jessen


@mathias in comments hit the nail on the head!

bunch of stuff | Stop-Service -WarningAction SilentlyContinue
like image 32
Kazic Avatar answered Oct 27 '25 00:10

Kazic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!