Pages

7/30/2013

Powershell - Change Service Startup Type

Powershell: Change Windows Service Startup Type of Remote Server

Works with Powershell 1.0 & 2.0

 #Check Startup Type
 ($svc = Get-WmiObject Win32_Service -ComputerName $server -Filter "name='wuauserv'") | out-null
 if ($svc.StartMode -eq "Disabled") {
     "$server WSUS service changed to Automatic"
     $result=$svc.changestartmode("Automatic")
 }#end if

 #Backup Service Registry
 $result=([WmiClass]"\\$server\ROOT\CIMV2:Win32_Process").create("c:\windows\regedit /e c:\WSUS.REG HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\wuauserv")
 write $server "Backup Service Registry RESULT=" $result.returnvalue
 
 #Set Service as Delayed Start
 write $server "configure service"
 $key = "SYSTEM\CurrentControlSet\Services\wuauserv"
 $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $server)
 $regKey = $reg.OpenSubKey($key, $true)
 $result = $regKey.setvalue("DelayedAutoStart", "1", "DWORD")

No comments: