Description

I have updated one of old Powershell scripts (http://portal.sivarajan.com/2010/07/stopstart-or-enabledisable-service.html) based on a comment posted on my blog.  You can also check the status of service by verifying the $result.ReturnValue value.  The Win32_Service Class reference can be found in the following location:

http://msdn.microsoft.com/en-us/library/aa393673(v=vs.85).aspx

 

Script

PowerShell
Edit|Remove
<# www.sivarajan.com 
blog.sivarajan.com 
#> 
cls 
$OutputFile = New-Item -type file -force "C:\Scripts\ServiceOutput.csv" 
$Cred = Get-Credential 
$service = "mpssvc" 
Import-CSV C:\Scripts\input.csv | % {  
$computer = $_.ComputerName 
$result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $cred).stopservice() 
    If ($result.ReturnValue -eq "0")  
    { 
    write-host "$Computer -> Service Stopped Successfully" 
    "$Computer -> Service Stopped Successfully" | Out-File $OutputFile -encoding ASCII -append 
    #$result.ReturnValue info: http://msdn.microsoft.com/en-us/library/aa393673(v=vs.85).aspx 
    } 
} 
 
<# 
$result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $cred).startervice() 
$result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $cred).ChangeStartMode("Disabled") 
$result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $cred).ChangeStartMode("Automatic") 
#>