Monday, May 30, 2016

Using Windows PowerShell to Start Service Which Stopped

#Start all non-running Auto services
#C:\Users\duke\Documents
#taskschd.msc

#Step 1: Run One Time
#Set-ExecutionPolicy -Scope LocalMachine Unrestricted

#Step 2: Create a batch file like:  PowerShell -noexit -file "C:\Users\duke\Documents\rstart.ps1", add to windows Scheduler
$Computer = “WIN-36TFBPF3FHK”
$ServiceName = 'webclient'
#stop-service $ServiceName
#get-service -name $ServiceName
Get-WmiObject win32_service -ComputerName $computer -Filter " state != 'running' AND name = '$ServiceName'" | Invoke-WmiMethod -Name StartService
#get-service -name $ServiceName

No comments:

Post a Comment