Showing posts with label Restart SharePoint Service. Show all posts
Showing posts with label Restart SharePoint Service. Show all posts

Monday, July 9, 2012

Start a specific service on all SharePoint Servers in a FARM (WFE and APP Servers) using PowerShell


//Services Like SPTimerV4, SPAdminV4, iisadmin, W3SVC, WAS
        $serviceName = "Name of the service to be started"
        // Loop thru all the servers in a SharePoint Farm
        foreach ($server in (get-spserver | Where {$_.Role -ne "Invalid"}) )
        {
            Write-Host Restarting $serviceName in $server.Name
            $service = Get-WmiObject -computer $server.Name Win32_Service -Filter "Name='$serviceName'"
            $service.InvokeMethod('StopService',$Null)
            Start-Sleep -s 5
            $service.InvokeMethod('StartService',$Null)
            Start-Sleep -s 5
            $service.State           
        }