[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2014-08-18
8
Medium Priority
?
574 Views
Last Modified: 2014-09-12
I am looking for a sample powershell script to turn off/on services on multiple servers from a central location. Greatly appriciate it.
0
Comment
Question by:dongocdung
8 Comments
 
LVL 6

Assisted Solution

by:Chad Franks
Chad Franks earned 668 total points
ID: 40268744
I have used this site in the past for these types of scripts.  This will break it down into a text file with a list of servers, manually entering the server names etc...

https://4sysops.com/archives/restart-a-service-on-multiple-remote-computers-using-powershell/
0
 
LVL 8

Expert Comment

by:Shahnawaz Ahmed
ID: 40268747
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.
0
 
LVL 29

Assisted Solution

by:becraig
becraig earned 664 total points
ID: 40268817
There are many ways to accomplish this, are you wanting to check service state etc  before performing an action ?

e.g. if service is not running and service is disabled - set service to - automatic then start etc

of you just want basic start service on computer A (If so this can be done via command line as well)
for /f %a in (serverlist.txt) do sc \\%a start servicename 

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:dongocdung
ID: 40286394
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?
0
 
LVL 29

Expert Comment

by:becraig
ID: 40286409
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

0
 

Author Comment

by:dongocdung
ID: 40286461
I don't think our environment allows us to run sc tool. Is there any other ways we can run it?
0
 
LVL 29

Expert Comment

by:becraig
ID: 40286465
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.
0
 
LVL 14

Accepted Solution

by:
Justin Yeung earned 668 total points
ID: 40300168
@Shahnawaz Ahmed
your command is incorrect =P

to start a service by using start-service will require powershell remoting turned on on the target machine.

and it could be done this way. (where abc,bcd,dce are the computers)

invoke-command -computername abc,bcd,dce {start-service -Name "whatever services"}

Open in new window

0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Loops Section Overview
Screencast - Getting to Know the Pipeline

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question