The not-nearly-updated-often-enough blog of Brian Lalancette

Powershell script to enable/disable services in SP2010 Demo VM

February 03, 2010 by Brian Lalancette

If any of you have had the chance to play around with Microsoft’s recent public release of the Information Worker Demo VM, you’ll notice that a) it has pretty much everything thrown in in terms of the Office suite of server/client products and b) it’s a hog! At idle, the VM will start to consume almost 10GB RAM (combined physical and virtual/paging) within minutes of booting up. For developers and sysadmins used to running (2 or 3) 32-bit MOSS2007 Virtual PCs concurrently on your laptop, the new resource requirements for SP2010 can be quite a shock. How can we trim and optimize the resources the demo VM uses? By turning off services we don’t immediately need…

For example, if you want to develop/demo SharePoint 2010 stuff only, but don’t care about Office Communications Server, you can turn all of these services (and the supporting SQL instance) off, and free up quite a bit of RAM. However, you might want to change this in a different scenario, so that only the OCS services are running but the SharePoint stuff is off. This could get pretty tedious if we were simply using the Services MMC each time!

Using a Powershell script though, we can quickly enable/start or disable/stop different services on our demo VM, just in time for its intended use at any particular time. The script below can easily be further customized to allow for greater granularity over what services are controlled, etc. Consider it a starting point towards getting only the services you want running at any particular time on a machine with limited resources.

[UPDATE] - turns out Emmanuel Bergerat had already released scripts with very similar functionality, way back in November! Definitely check these out for another approach to freeing up resources on a SP2010 install.

Hope you find it useful! Oh and watch the line breaks and double quotes when copying/pasting…

## Stop-Start-Services.ps1 by Brian Lalancette ## Originally intended for SP2010 IW Demo VM

Function StopUnneededServices { Write-Host -ForegroundColor Blue ”- Stopping services…” #Permanent service stoppage - you likely wont need these in the demo VM $ServicesToSetManual = (“Spooler”,"AudioSrv", “TabletInputService”,"UxSms", “ftpsvc”,"MSSQLFDLauncher", “SQLSERVERAGENT”) $ServicesToDisable = (“WPDBusEnum”,"WerSvc", “WSearch”) Write-Host -ForegroundColor Blue ”- Setting some unneeded services to Manual start…” ForEach ($SvcName in $ServicesToSetManual) { If (Get-Service -Name $SvcName -ErrorAction SilentlyContinue) { Stop-Service -Name $SvcName -Force Set-Service -Name $SvcName -StartupType Manual Write-Host -ForegroundColor Blue ” - Service $SvcName is now set to Manual start” } } Write-Host -ForegroundColor Blue ”- Disabling some unneeded services…” ForEach ($SvcName in $ServicesToDisable) { If (Get-Service -Name $SvcName -ErrorAction SilentlyContinue) { Stop-Service -Name $SvcName -Force Set-Service -Name $SvcName -StartupType Disabled Write-Host -ForegroundColor Blue ” - Service $SvcName is now disabled.” } } }

Function StopSPServices { #Temporary SP demo service stoppage; use actual service name, not display (long) name $ServicesToDisable = (“FASTSearchService”,"FASTSearchMonitoring", “ProjectEventService14”,"ProjectQueueService14", “WebAnalyticsService”,"SPAdminV4", “SPTimerV4”,"SPTraceV4", “SPAdminV4”,"SPUserCodeV4", “OSearch14”,"FIMService", “FIMSynchronizationService”,"MSSQLSERVER", “MSSQLServerOLAPService”,"MSDtsServer100", “ReportServer”,"SQLWriter", “W3SVC”,` “IISADMIN”) Write-Host -ForegroundColor Blue ”- Disabling SP demo services…” ForEach ($SvcName in $ServicesToDisable) { If (Get-Service -Name $SvcName -ErrorAction SilentlyContinue) { Stop-Service -Name $SvcName -Force Set-Service -Name $SvcName -StartupType Disabled Write-Host -ForegroundColor Blue ” - Service $SvcName is now disabled.” } } Write-Host -ForegroundColor White ”- Finished disabling SP demo services.” }

Function StopFASTServices { #Temporary FAST service stoppage; use actual service name, not display (long) name $ServicesToDisable = (“FASTSearchService”,` “FASTSearchMonitoring”) Write-Host -ForegroundColor Blue ”- Disabling FAST services…” ForEach ($SvcName in $ServicesToDisable) { If (Get-Service -Name $SvcName -ErrorAction SilentlyContinue) { Stop-Service -Name $SvcName -Force Set-Service -Name $SvcName -StartupType Disabled Write-Host -ForegroundColor Blue ” - Service $SvcName is now disabled.” } } Write-Host -ForegroundColor White ”- Finished disabling FAST services.” }

Function StopOCSServices { If (Get-Service -Name ‘MSSQL$RTC’ -ErrorAction SilentlyContinue) { Write-Host -ForegroundColor Blue ”- Disabling OCS demo services…” Set-Service -Name ‘MSSQL$RTC’ -StartupType Disabled Stop-Service -Name ‘MSSQL$RTC’ Get-Service | ?{$.DisplayName -like “Office Communications*”} | Set-Service -StartupType Disabled Get-Service | ?{$.DisplayName -like “Office Communications*”} | Stop-Service Write-Host -ForegroundColor White ”- Finished disabling OCS services.” } }

Function StartSPServices { $ServicesToSetAutomatic = (“FASTSearchService”,"FASTSearchMonitoring", “MSSQLSERVER”,"MSSQLServerOLAPService", “MSDtsServer100”,"ReportServer", “SQLWriter”,"W3SVC", “ProjectEventService14”,"ProjectQueueService14", “WebAnalyticsService”,"SPAdminV4", “SPTimerV4”,"SPTraceV4", “SPAdminV4”,"SPUserCodeV4", “FIMService”,"FIMSynchronizationService", “OSearch14”,` “IISADMIN”) Write-Host -ForegroundColor Blue ”- Re-enabling SP demo services…” ForEach ($SvcName in $ServicesToSetAutomatic) { If (Get-Service -Name $SvcName -ErrorAction SilentlyContinue) { Set-Service -Name $SvcName -StartupType Automatic Start-Service -Name $SvcName Write-Host -ForegroundColor Blue ” - Service $SvcName is now set to Automatic start” } } Write-Host -ForegroundColor White ”- Finished re-enabling SP demo services.” }

Function StartOCSServices { If (Get-Service -Name ‘MSSQL$RTC’ -ErrorAction SilentlyContinue) { Write-Host -ForegroundColor Blue ”- Re-enabling OCS demo services…” Set-Service -Name ‘MSSQL$RTC’ -StartupType Automatic Start-Service -Name ‘MSSQL$RTC’ Get-Service | ?{$.DisplayName -like “Office Communications*”} | Set-Service -StartupType Automatic Get-Service | ?{$.DisplayName -like “Office Communications*”} | Start-Service Write-Host -ForegroundColor White ”- Finished re-enabling OCS demo services.” } }

Function ChooseOption { $Choice = Read-Host “Please select:n (1) - Stop ALL demo servicesn (2) - Stop OCS demo servicesn (3) - Stop SharePoint demo servicesn (4) - Stop FAST servicesn (5) - Start ALL demo servicesn (6) - Start OCS demo servicesn (7) - Start Sharepoint demo servicesn (0) - QUITn Choice”

Switch ($Choice) { “1” {StopUnneededServices;StopSPServices;StopOCSServices;ChooseOption} “2” {StopUnneededServices;StopOCSServices;ChooseOption} “3” {StopUnneededServices;StopSPServices;ChooseOption} “4” {StopFASTServices;ChooseOption} “5” {StartSPServices;StartOCSServices;ChooseOption} “6” {StartOCSServices;ChooseOption} “7” {StartSPServices;ChooseOption} “0” {break} default {Write-Host -ForegroundColor Red ”- Please select a valid option…“;ChooseOption} } If ($Choice -eq “0”) {break} }

$Choice If ($Choice -ne “0”) {ChooseOption}

Write-Host “Press any key to exit…” $x = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)


Written by Brian Lalancette

Hey fellow Sharepointers/Powershellers/infrastru… ah never mind. My name is Brian Lalancette, and I’m a Premier Field Engineer (PFE) at Microsoft Canada.

This blog is a long time coming, and a realization of my New Year’s resolution for 2010 – to share some of the knowledge about SharePoint, server virtualization/infrastructure, and other tidbits I’ve picked up over my 18+ years in IT. Hope it can help some of you out, and always looking forward to hearing your thoughts & comments. All posts and info are provided without warranty, etc. etc. and I’m not responsible for blowing up your or my production servers, deleting all your data, or leaving coffee stains on your desk and crumbs in your keyboard.

Cheers! Brian

You should follow Brian on Twitter