Bulk start, stop, disable of windows services

Sharing a script that we have used recently for stopping/starting exchange services & setting those to disabled/enabled for some hardware maintenance work. This script has been enhanced to be used with any of the windows services.

Extract the script zip from below link & update the servers.txt & services.txt that is placed inside the script folder.

ServiceSts.zip

 

Example of services file :

 

Example of servers file:

 

Ones both the files have been updated, you just have to run the batch file & it will prompt you for status/ startup that you want to set.

 

As you can see in the above screenshot , values for status can be : stopped or running

Values for startuptype can be : manual, stopped, disabled

If you enter values other than these, than script will exit by throwing error as below:

 

Let us now enter the correct values for the parameters: for example – stopped & disabled

Press return to execute..

 

All services have been stopped & set to disabled.

 

 

similarly after maintenance of hardware is completed, you can use Running & automatic as values.

Note:- Use PS version 3.0 or above

################################################################################### 
#            Author: Vikas Sukhija http://techwizard.cloud 
#            Date: 11/12/2015 
#            Update:11/28/2015 
#            Reviewer: 
#            Description: Start, stop, disable ,manual, automatic 
################################################################################### 
 
param( 
     
$status$startup 
) 
 
write-host "After updating the servers & Services file" -foregroundcolor Magenta 
write-host "Use Script as setsvssts.ps1 startuptype status" -foregroundcolor Magenta 
write-host "-----------------------------------------------" -foregroundcolor Magenta 
write-host "--------Examples--------" -foregroundcolor Magenta 
write-host "Use Script as setsvssts.ps1 stopped manual" -foregroundcolor Magenta 
write-host "Use Script as setsvssts.ps1 stopped automatic" -foregroundcolor Magenta 
write-host "Use Script as setsvssts.ps1 stopped disabled" -foregroundcolor Magenta 
write-host "Use Script as setsvssts.ps1 running manual" -foregroundcolor Magenta 
write-host "Use Script as setsvssts.ps1 running manual" -foregroundcolor Magenta 
 
write-host "=========================================== " -foregroundcolor Blue 
 
 
write-host "You can also enter parameters when Prompted " -foregroundcolor Blue 
 
$servers = gc .\servers.txt 
$services = gc .\services.txt 
 
if(($status -like "stopped"-or ($status -like "running")){ }else{ 
    $status = Read-host "Refer above and Enter Value for status:"  
    if(($status -like "stopped"-or ($status -like "running")){ }else{ 
    Write-Host "You have entered invalid input, script will end now" -foregroundcolor Red 
    timeout 10 
    exit} 
} 
 
if(($startup -like "manual"-or ($startup -like "automatic"-or ($startup -like "disabled")){ }else{ 
    $startup = Read-host "Refer above and Enter Value for startuptype:"  
    if(($startup -like "manual"-or ($startup -like "automatic"-or ($startup -like "disabled")){ }else{ 
    Write-Host "You have entered invalid input, script will end now" -foregroundcolor Red 
    timeout 10 
    exit} 
} 
 
$servers | foreach-object { 
Write-host "Processing ....................... $_" 
$comp = $_ 
 
$services | foreach-object { 
$svc = $_ 
$comp 
$svc 
 
Set-Service -ComputerName $comp -Name $svc -StartupType $startup 
if$status -like "stopped"){ 
get-service -ComputerName $comp -Name $svc | Stop-Service -force} 
 
if$status -like "running"){ 
get-service -ComputerName $comp -Name $svc | Start-Service} 
 
 
} 
 
} 
####################################################################################

 

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

 

3 thoughts on “Bulk start, stop, disable of windows services

  1. Hello Vikas,

    Could you please help me to writing a script, which is monitor the multiple Services from one server and sent the report to me through mail if the service is down.

    I have placed the required services in services.txt

    I tried so many options but failing 😦

    Regards,
    Chandra

  2. Thanks Vikas. I tried it it is working for me, but can we notify only which is not running. For example IIS ADMIN is running and WWW service is not running. I need to get the alert only for WWW service.

Leave a comment