Tuesday, 21 June 2011

using PowerShell v2 remoting to restart SharePoint services on all the WFE servers in the farm

First - put the servers into an array:
[Void][System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")

$farm = ([Microsoft.SharePoint.Administration.SPFarm]::Local`

%{ $_.Services} `

?{$_.typename -eq "Windows SharePoint Services Web Application"}`

%{$_.instances} `

%{$_.Server} `

%{$_.Address}

)

$farm


Then use a Foreach loop to step through each server in the array and restart the services on each:

foreach ($i in $farm)


{

$session = New-PSSession -ComputerName $i

Invoke-Command -Session $session -ScriptBlock { Restart-Service Sptimerv3 }

Invoke-Command -Session $session -ScriptBlock { Restart-Service Spadmin }

}

Remember to configure the firewall correctly and to ensure WinRM is initialized and enabled for Kerberos on the remote machines

No comments:

Post a Comment