Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading