TheGeekery

The Usual Tech Ramblings

PowerShell: Restart Remote Services

In a follow up to @ScriptingGuys post about restarting services using VBScript, here is the same using PowerShell. I’ll probably be dragging the same onto some server monitoring stuff to get a service back up and running we’ve been having a weird issue with1.

1
2
3
4
5
6
7
8
9
$names = Get-Content c:\temp\computers.txt
foreach($name in $names) {
  $svc = Get-WmiObject Win32_Service -ComputerName $name `
      -Filter "name='wuauserv'"
  if ($svc.started -eq $true) {
      $svc.StopService()
  }
  $svc.StartService()
}

This takes a file “computers.txt”, loops through the data, and uses WMI to connect to the remote machines to get the wuauserv service (or in plain English Windows Automatic Update). Easy as pie.


  1. Service has just been vanishing, no logs that it has stopped, crashed, or anything

Comments