Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 999
  • Last Modified:

Powershell Script to Stop / Start / Restart Windows Cluster Services

Looking for a Powershell Script that would take the content of server names in a .txt file and Stop / Start / Restart Windows Cluster Services on 2003, 2008, and 2012
0
mjm21
Asked:
mjm21
  • 2
  • 2
2 Solutions
 
OriNetworksCommented:
Put a list of hosts in a txt file. Replace MyService with the name of the service you want to restart.
$hosts = Get-Content MyHosts.txt
foreach ($i in $hosts)
{
Write-Output "restarting service on $i"
Get-Service -Name MyService -ComputerName $i | Stop-service
Get-Service -Name MyService -ComputerName $i | Start-service
}

Open in new window

0
 
mjm21Author Commented:
Great!  Let me test
0
 
mjm21Author Commented:
Works great on my local machine but did not work on my remote neighbor's.
0
 
Joshua GrantomSenior EngineerCommented:
Hello mjm21 and OriNetworks,

Here is a slightly different method. Let me know if this works better, its based off of another question I helped with

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/Q_28523050.html

$hosts = Get-Content MyHosts.txt
foreach ($i in $hosts)
{
Write-Output "restarting service on $i"
Restart-Service -InputObject $(Get-Service -Computer $i -Name MyService)
}

Open in new window

0
 
OriNetworksCommented:
Just an fyi: you would need the proper rights on the remote system to restart the service possibly by being a local administrator in order for this to work. Thanks Joshua for the enhanced version.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now