Link to home
Start Free TrialLog in
Avatar of dongocdung
dongocdung

asked on

Using powershell to turn off/on service multiple servers from a central location

I am looking for a sample powershell script to turn off/on services on multiple servers from a central location. Greatly appriciate it.
SOLUTION
Avatar of Chad Franks
Chad Franks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Shahnawaz Ahmed
Dear dongocdung,

$ComputerName = Get-Content d:\test.txt

foreach($computers in $ComputerName){

start service BITS



}



d:\test.txt   = this is the location where you need to put the test.txt file in which you need to mention all servers name on which you want to stop/start the services.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dongocdung
dongocdung

ASKER

I was able to run the script locally on the server but when I ran it from a central location, the script did not work. What could the reason why I couldn't run it from a central location?
I am not sure what you mean a central location ?

The input is simple:
1. serverlist.txt - will be a file with all the servernames in (one on each line)
2. you will have to specify the service name on the command line


e.g
for /f %a in (\\uncpath\C$\folder\serverlist.txt) do sc \\%a start servicename 

Open in new window

I don't think our environment allows us to run sc tool. Is there any other ways we can run it?
sc is not a tool, it is a "built-in" windows command.

If SC is not working in your environment I am not sure what else would work if basic windows commands do not work for you.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial