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.

$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) {

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