Start & Stop SharePoint 2010 Windows Services

If you are a SharePoint developer, most probably you installed SharePoint Server to your development environment and if you don’t have seperate development server or you’re not rich like me, you ended up with memory shortage. As most of you know SharePoint consumes considerable amount of resources especially memory.
So here is my situation. I have a laptop for development containing the whole SharePoint development toolset (SharePoint Server, SQL Server, Visual Studio etc.). But since I’m not working with SharePoint all the time, I want to free the resources SharePoint allocates when I’m not actively using it.
I made a search on the web and found the nice post written by Emmanuel Bergerat from Microsoft Canada. He has written these three PowerShell scripts to:

  1. Set the SharePoint 2010 related default services “Startup type” as I wanted (i.e. “Manual”) – used once.
  2. Start those Services when SharePoint 2010 is needed
  3. Stop those same Services when SharePoint 2010 is not needed anymore

Here you can find the original post by Emmanuel: http://blogs.msdn.com/b/emberger/archive/2009/11/16/stop-and-go-with-sharepoint-2010-on-your-workstation.aspx

I made some little changes on second and third scripts in order to stop and start specific IIS web sites which is related with SharePoint. Here are the modified scripts:

Change Startup Type of the SharePoint 2010 Related Services

# SharePoint 2010 Workstation START up type modification script
#
# Scripts written by Emmanuel Bergerat (emberger@microsoft.com) on Oct. 20th 2009
# Provided as is, and can be freely modified and distributed
# Enjoy!
# 

"Setting all SharePoint 2010 related services to Manual Startup:"
# SQL Services set to Manual Startup
"MSSQLSERVER","SQLWriter","SQLSERVERAGENT" | ForEach-Object {
    Set-Service $_ -startuptype manual}
    "  - SQL Services set to Manual StartUp" 

# IIS Service to Manual Startup
Set-Service "W3SVC" -startuptype manual    
"  - IIS Service set to Manual StartUp" 

# SharePoint services set to Manual Startup
"SPTimerV4","DCLoadBalancer14","DCLauncher14","SPWriterV4","SPUserCodeV4","SPTraceV4","SPAdminV4","WebAnalyticsService" | ForEach-Object {    
Set-Service $_ -startuptype manual}    
"  - SharePoint Services set to Manual StartUp" 

# SharePoint Search set to Manual Startup
"OSearch14", "SPSearch4"| ForEach-Object {    
Set-Service $_ -startuptype manual}    
"  - SharePoint Search set to Manual StartUp"
" "
"All SharePoint 2010 related services are now set to Manual Startup"

Start SharePoint 2010 Services

# SharePoint 2010 Local Dev Workstation Services START script
#
# Scripts written by Emmanuel Bergerat (emberger@microsoft.com) on Nov. 24th 2009
# Provided as is, and can be freely modified and distributed
# Enjoy!
#

Import-Module WebAdministration 

# Start local SQL Services
"Starting Local SQL Services"
"MSSQLSERVER","SQLWriter","SQLSERVERAGENT" | ForEach-Object {
    $servicePrior = get-service $_
    "$_ is " + $servicePrior.status + " and will be Started"
    Start-Service $_
    $serviceAfter = get-service $_
    "$_ is now " + $serviceAfter.status }
"=> Local SQL Services Started"
" "

# Start IIS
#"Starting IIS"
#"W3SVC" | ForEach-Object {
#    $servicePrior = get-service $_
#    "$_ is " + $servicePrior.status + " and will be Started"
#    Start-Service $_
#    $serviceAfter = get-service $_
#    "$_ is now " + $serviceAfter.status }

"Starting SharePoint Related IIS Web Applications"
$sites = dir “IIS:\Sites”   
foreach ($webapp in $sites)
{
    $name = $webapp.Name
    if ($name -like "SharePoint*")
    {
    "Starting " + $name
    Start-WebSite -Name $name
    }
}

"=> SharePoint Applications are started"
" "

# Start SharePoint 2010 Services
"Starting SharePoint Server 2010"
"SPTimerV4","DCLoadBalancer14","DCLauncher14","SPWriterV4","SPUserCodeV4","SPTraceV4","SPAdminV4","WebAnalyticsService" | ForEach-Object {
    $servicePrior = get-service $_
    "$_ is " + $servicePrior.status + " and will be Started"
    Start-Service $_
    $serviceAfter = get-service $_
    "$_ is now " + $serviceAfter.status }
"=> SharePoint Server 2010 is Started"
" "

# Start SharePoint Search
"Starting SharePoint Search 2010"
"OSearch14","SPSearch4" | ForEach-Object {
    $servicePrior = get-service $_
    "$_ is " + $servicePrior.status + " and will be Started"
    Start-Service $_
    $serviceAfter = get-service $_
    "$_ is now " + $serviceAfter.status }
"=> SharePoint Search 2010 is Started"
" "
"Warming up local SharePoint WebApplications"
$snapin = Get-PSSnapin | Where-Object { $_.Name -like "Microsoft.SharePoint.PowerShell"}
if ([bool]$snapin) {} else {Add-PsSnapin Microsoft.SharePoint.PowerShell}
function Warmup-Site([string]$url)
{
	$wc = New-Object net.WebClient
    $wc.credentials = [System.Net.CredentialCache]::DefaultCredentials;
	return $wc.DownloadString($url)
}
Get-SPWebApplication -IncludeCentralAdministration | Get-SPSite | ForEach-Object { Write-Host "Warming up site:" $_.Url ; $html = Warmup-Site -url $_.Url}
"=> Local SharePoint sites warmed up"
" "
"=> SharePoint 2010 is started on this workstation... Do you still have free RAM? :-) <="

Stop SharePoint 2010 Services

# SharePoint 2010 Local Dev Workstation Services STOP script
#
# Scripts written by Emmanuel Bergerat (emberger@microsoft.com) on Nov. 24th 2009
# Provided as is, and can be freely modified and distributed
# Enjoy!
#

Import-Module WebAdministration 

# Stop SharePoint Search
"Stopping SharePoint Search 2010"
"OSearch14","SPSearch4" | ForEach-Object {
    $servicePrior = get-service $_
    "$_ is " + $servicePrior.status  + " and will be stopped"
    Stop-Service $_ -Force
    $serviceAfter = get-service $_
    "$_ is now " + $serviceAfter.status }
"=> SharePoint Search 2010 is STOPPED"
" "
# Stop SharePoint 2010 Services
"Stopping SharePoint Server 2010"
"SPTimerV4","DCLoadBalancer14","DCLauncher14","SPWriterV4","SPUserCodeV4","SPTraceV4","SPAdminV4","WebAnalyticsService" | ForEach-Object {
    $servicePrior = get-service $_
    "$_ is " + $servicePrior.status  + " and will be stopped"
    Stop-Service $_ -Force
    $serviceAfter = get-service $_
    "$_ is now " + $serviceAfter.status }
"=> SharePoint Server 2010 is STOPPED"
" "
# Stop IIS
#"Stopping IIS"
#"W3SVC" | ForEach-Object {
#    $servicePrior = get-service $_
#    "$_ is " + $servicePrior.status  + " and will be stopped"
#    Stop-Service $_ -Force
#    $serviceAfter = get-service $_
#    "$_ is now " + $serviceAfter.status }
#iisreset
"Stoping SharePoint Related IIS Web Applications"
$sites = dir “IIS:\Sites”   
foreach ($webapp in $sites)
{
    $name = $webapp.Name
    if ($name -like "SharePoint*")
    {
    "Starting " + $name
    Stop-WebSite -Name $name
    }
}

"=> SharePoint Applications are stoped"
" "
# Stop local SQL Services
"Stopping Local SQL Services"
"MSSQLSERVER","SQLWriter","SQLSERVERAGENT" | ForEach-Object {
    $servicePrior = get-service $_
    "$_ is " + $servicePrior.status  + " and will be stopped"
    Stop-Service $_ -Force
    $serviceAfter = get-service $_
    "$_ is now " + $serviceAfter.status }
"=> Local SQL Services STOPPED"
" "
"=> SharePoint 2010 is STOPPED on this workstation... you can use it now... with more RAM ;-) <="

Hope this helps..

Leave a comment

Your email address will not be published.

%d bloggers like this: