{"id":1788,"date":"2015-04-29T22:50:09","date_gmt":"2015-04-29T21:50:09","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=1788"},"modified":"2015-04-29T22:50:09","modified_gmt":"2015-04-29T21:50:09","slug":"restart-services-script","status":"publish","type":"post","link":"https:\/\/www.stuartroberts.net\/index.php\/2015\/04\/29\/restart-services-script\/","title":{"rendered":"Restart Services Script"},"content":{"rendered":"<p>Looking for a PowerShell script to restart important services across a SharePoint farm?  Look no further because all you need is here \ud83d\ude42<\/p>\n<p>The script below, initiated by calling the <em>Restart-Services<\/em> function, restarts the following services on all SharePoint servers in the farm:<\/p>\n<ul>\n<li>SharePoint Timer<\/li>\n<li>World Wide Web Publishing Service<\/li>\n<li>IIS Admin Service<\/li>\n<li>SharePoint Administration<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<pre lang=\"powershell\">\r\nfunction Restart-Services {\r\n\t[Array]$servers= Get-SPServer | ? {$_.Role -ne [Microsoft.SharePoint.Administration.SPServerRole]::Invalid}\r\n\t\r\n\tforeach ($server in $servers) {\r\n\t\tRestart-ServiceArray $server\r\n\t}\r\n}\r\n\r\nfunction Restart-ServiceArray {\r\n\t[CmdletBinding()]\r\n\tparam([parameter(Position=1, Mandatory=$true)][Microsoft.SharePoint.Administration.SPServer]$server)\r\n\tprocess {\r\n\t\t[Array] $services = \"SPTimerV4\", \"W3SVC\", \"IISADMIN\", \"SPAdminV4\"\r\n\t\t\r\n\t\tforeach($serviceName in $services) {\r\n\t\t\t$serviceInstance = Get-Service -ComputerName $server.Name -Name $serviceName -ErrorAction SilentlyContinue\r\n\t        \tif($serviceInstance -ne $null) {\r\n\t\t\t\tWrite-Host (\"Restarting \", $serviceName, \" on \", $server -join \"\")\r\n\t\t\t\tRestart-Service -InputObject $serviceInstance -Force\r\n\t\t\t\tWrite-Host \"Done`n\" -ForegroundColor Green\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tWrite-Host (\"Could not find \", $serviceName, \" on \", $server -join \"\") -ForegroundColor Red\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>Simply add any additional services you want to restart to the <em>$services<\/em> array in the <em>Restart-ServiceArray<\/em> function and away you go!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Looking for a PowerShell script to restart important services across a SharePoint farm? Look no further because all you need is here \ud83d\ude42 The script below, initiated by calling the Restart-Services function, restarts the following services on all SharePoint servers &hellip; <a href=\"https:\/\/www.stuartroberts.net\/index.php\/2015\/04\/29\/restart-services-script\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[3],"tags":[41,81],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-sQ","_links":{"self":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1788"}],"collection":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=1788"}],"version-history":[{"count":3,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1788\/revisions"}],"predecessor-version":[{"id":1791,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1788\/revisions\/1791"}],"wp:attachment":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}