Windows PowerShell Script: How to stop multiple windows services

Windows PowerShell Script: How to stop multiple windows services

If for some reason you might find yourself in the situation that you need an elegant method of stopping a bunch of windows services automagically you can always turn for help to the friendly and almighty Windows PowerShell…

# Get a list of Windows services with a specific filter criteria
$services = Get-Service |
    Where-Object {$_.displayname -like "BloatedWithUselessServicesAntivirusName*"}

# Iterate through the bastard list of memory consuming services
if ($service -ne $null)
{
    foreach ($service in $services)
    {
        # Get the service name
        echo $service.name 

        # Kill it with a passion or ...
        Stop-Service -Name $service.name 
        
        # Start it with hatred
        #Start-Service -Name $service.name 
    }
}
else
{
    echo "You are in luck, you don't have crappy av installed"
}

PS: in case your working environments security policy is constipated administer the following pill in a ps ISE with admin rights:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned
8. iulie 2013, 23:17 details & comments (0) Tagged with: , , The permalink address (URI) of this photo is: https://www.alexandrusavu.ro/2013/07/08/windows-powershell-script-how-to-stop-multiple-windows-services/

Comments (0)

Be the first to comment!

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>