{"id":478,"date":"2019-06-12T13:19:00","date_gmt":"2019-06-12T18:19:00","guid":{"rendered":"http:\/\/itblog.ldlnet.net\/?p=478"},"modified":"2019-06-12T15:27:21","modified_gmt":"2019-06-12T20:27:21","slug":"how-to-stop-and-start-all-sharepoint-2013-farm-services-using-powershell","status":"publish","type":"post","link":"https:\/\/itblog.ldlnet.net\/index.php\/2019\/06\/12\/how-to-stop-and-start-all-sharepoint-2013-farm-services-using-powershell\/","title":{"rendered":"How to Stop and Start All SharePoint 2013 Farm Services using PowerShell"},"content":{"rendered":"\n<p>How to Stop and Start All SharePoint 2013 Farm Services using PowerShell?&nbsp;<\/p>\n\n\n\n<p>Prior to SharePoint patching, its a best practice to Stop all SharePoint 2013 and its related services and then start once patching is completed. If you don&#8217;t do this, your service pack or patch installation will take longer than its expected.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>So what are all the services to be stopped?<\/strong><\/p>\n\n\n\n<p> \u2022 <strong>SharePoint 2013 Search Service (OSearch15 &#8211; OSearch16 in SharePoint 2016)<\/strong><\/p>\n\n\n\n<p> \u2022 <strong>SharePoint 2013 Timer Job (SPTimerV4) \u2022 SharePoint 2013 Administration (SPAdminV4) <\/strong><\/p>\n\n\n\n<p>\u2022 <strong>SharePoint 2013 Tracing (SPTraceV4) <\/strong><\/p>\n\n\n\n<p>\u2022 <strong>SharePoint 2013 VSS Writer (SPWriterV4) <\/strong><\/p>\n\n\n\n<p>\u2022 <strong>SharePoint 2013 User Code Host (SPUserCodeV4) <\/strong><\/p>\n\n\n\n<p><strong>\u2022 SharePoint Search Host Controller (SPSearchHostController) <\/strong><\/p>\n\n\n\n<p><strong>\u2022 Forefront Sync Service (FIMSynchronizationService) <\/strong><\/p>\n\n\n\n<p>\u2022 <strong>Forefront Service (FIMService) <\/strong><\/p>\n\n\n\n<p>\u2022 <strong>World Wide Web Publishing Service (W3SVC<\/strong>) <\/p>\n\n\n\n<p>\u2022 <strong>Internet Information Services (IIS) <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"460\" src=\"https:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2019\/06\/image-9.png\" alt=\"\" class=\"wp-image-486\" srcset=\"https:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2019\/06\/image-9.png 624w, https:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2019\/06\/image-9-300x221.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><figcaption>Don&#8217;t forget to do it in all your SharePoint Servers of the farm!<br><\/figcaption><\/figure>\n\n\n\n<p>Lets use PowerShell to stop and start all SharePoint services:<\/p>\n\n\n\n<p><strong>Stop all SharePoint 2013 Services<\/strong>, Lets use PowerShell to stop and start all SharePoint services: <\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\tAdd-PSSnapin Microsoft.sharepoint.powershell -ErrorAction SilentlyContinue\n2\t\u00a0\n3\t$SharePointServices = ('SPSearchHostController','OSearch15','SPWriterV4','SPUserCodeV4','SPTraceV4','SPTimerV4','SPAdminV4','FIMSynchronizationService','FIMService','W3SVC')\n4\t\u00a0\n5\t#Stop all SharePoint Services\n6\tforeach ($Service in $SharePointServices)\n7\t{\n8\t\u00a0\u00a0\u00a0\u00a0Write-Host -ForegroundColor red \"Stopping $Service...\"\n9\t\u00a0\u00a0\u00a0\u00a0Stop-Service -Name $Service\n10\t}\n11\t\u00a0\n12\t#Stop IIS\n13\tiisreset \/stop\n<\/code><\/pre>\n\n\n\n<p><strong>Start all SharePoint 2013 Services<\/strong>: After the patching, Use the below script to start all SharePoint services.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\tAdd-PSSnapin Microsoft.sharepoint.powershell -ErrorAction SilentlyContinue\n2\t\u00a0\n3\t$SharePointServices = ('SPSearchHostController','OSearch15','SPWriterV4','SPUserCodeV4','SPTraceV4','SPTimerV4','SPAdminV4','FIMSynchronizationService','FIMService','W3SVC')\n4\t\u00a0\n5\t#Start all SharePoint Services\n6\tforeach ($Service in $SharePointServices)\n7\t{\n8\t\u00a0\u00a0\u00a0\u00a0Write-Host -ForegroundColor green \"Starting $Service...\"\n9\t\u00a0\u00a0\u00a0\u00a0Start-Service -Name $Service\n10\t}\n11\t\u00a0\n12\t#Start IIS\n13\tiisreset \/start\n<\/code><\/pre>\n\n\n\n<p><strong>Completely Stop or Start SharePoint Farm Services on All Servers: <\/strong>Lets put everything together and make a reusable PowerShell function, which stops or starts all SharePoint related services in all servers of the farm.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\tAdd-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue\n2\t\u00a0\n3\tFunction StartOrStop-SPFarm()\n4\t{\n5\t\u00a0\u00a0\u00a0\u00a0Param(\n6\t\u00a0\u00a0\u00a0\u00a0[parameter(Mandatory=$true)] $StartOrStopOption\n7\t\u00a0\u00a0\u00a0\u00a0)\n8\t\u00a0\n9\t\u00a0\u00a0\u00a0\u00a0#Get All Servers in the Farm \n10\t\u00a0\u00a0\u00a0\u00a0$Farm = Get-SPFarm\n11\t\u00a0\u00a0\u00a0\u00a0$Servers = $Farm.Servers | Where-Object {$_.Role -ne [Microsoft.SharePoint.Administration.SPServerRole]::Invalid} \n12\t\u00a0\u00a0\u00a0\u00a0Write-Host \"Total Number of Servers in the Farm: \" $Servers.Count \n13\t\u00a0\n14\t\u00a0\u00a0\u00a0\u00a0#List of All SharePoint Services\n15\t\u00a0\u00a0\u00a0\u00a0$SharePointServices = ('SPSearchHostController','OSearch15','SPWriterV4','SPUserCodeV4','SPTraceV4','SPTimerV4','SPAdminV4','FIMSynchronizationService','FIMService','W3SVC','DCLoadBalancer15', 'DCLauncher15')\n16\t\u00a0\n17\t\u00a0\u00a0\u00a0\u00a0#Iterate through each server\n18\t\u00a0\u00a0\u00a0\u00a0$Servers | ForEach-Object {\n19\t\u00a0\u00a0\u00a0\u00a0\u00a0Write-Host \"Performing Operation on Server:\" $_.Name\n20\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n21\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#Loop through each service\n22\t\u00a0\u00a0\u00a0\u00a0\u00a0foreach($ServiceName in $SharePointServices)\n23\t\u00a0\u00a0\u00a0\u00a0\u00a0{\n24\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$ServiceInstance = Get-Service -ComputerName $_.Name -Name $ServiceName -ErrorAction SilentlyContinue\n25\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if($ServiceInstance -ne $null)\n26\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n27\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0If($StartOrStopOption -eq \"Stop\")\n28\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n29\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Try \n30\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n31\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Write-Host \"Attempting to stop service\" $ServiceName \"..\" -ForegroundColor Yellow\n32\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Stop-Service -InputObject $ServiceInstance\n33\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Write-Host \"Stopped Service\" $ServiceName -ForegroundColor Green \n34\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n35\t\u00a0\n36\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0catch \n37\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n38\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Write-Host \"Error Occured on Stopping Service. \" $_.Message\u00a0 -ForegroundColor Red \n39\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n40\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n41\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0elseif ($StartOrStopOption -eq \"Start\")\n42\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n43\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Try \n44\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n45\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Write-Host \"Attempting to start service\" $ServiceName \"..\" -ForegroundColor Yellow\n46\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Start-Service -InputObject $ServiceInstance\n47\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Write-Host \"Started Service\" $ServiceName -ForegroundColor Green \n48\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n49\t\u00a0\n50\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0catch \n51\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n52\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Write-Host \"Error Occured on Starting Service. \" $_.Message\u00a0 -ForegroundColor Red \n53\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0\u00a0 \n54\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n55\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n56\t\u00a0\u00a0\u00a0\u00a0\u00a0}\n57\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#Start of Stop IIS\n58\t\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0If($StartOrStopOption -eq \"Stop\") { iisreset \/stop} elseif ($StartOrStopOption -eq \"Start\") {iisreset \/start}\n59\t\u00a0\u00a0\u00a0\u00a0}\n60\t}\n61\t\u00a0\n62\t#Call the function to Stop or Start Services\n63\tStartOrStop-SPFarm -StartOrStopOption \"Stop\"\n64\t#StartOrStop-SPFarm -StartOrStopOption \"Start\"\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Stop and Start All SharePoint 2013 Farm Services using PowerShell?&nbsp; Prior to SharePoint patching, its a best practice to Stop<\/p>\n<p class=\"link-more\"><a class=\"myButt \" href=\"https:\/\/itblog.ldlnet.net\/index.php\/2019\/06\/12\/how-to-stop-and-start-all-sharepoint-2013-farm-services-using-powershell\/\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":491,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[88,8,23,205],"class_list":["post-478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sharepoint","tag-o365","tag-powershell","tag-sharepoint","tag-sharepoint-online","odd"],"_links":{"self":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/comments?post=478"}],"version-history":[{"count":5,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/478\/revisions"}],"predecessor-version":[{"id":495,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/478\/revisions\/495"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/media\/491"}],"wp:attachment":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/media?parent=478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/categories?post=478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/tags?post=478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}