Manage Microsoft SharePoint 2010 instance on dev’s workstation.

When I setup the SharePoint 2010 on Windows7 x64 system I was quite satisfied by my laptop performance but as development and customization begins, IIS, Windows Services and SharePoint instance became more resource intense. See the following task manager graph it tells the major difference.

system memory before sharepoint server 2010Stats before SharePoint 2010. system memory after sharepoint is startedStats after SharePoint 2010 installation.

Though I use to work in SharePoint occasionally so I don’t need the instance running 24/7 on my development machine. While looking in to the core I figure out that we need couple of SharePoint\SQL(SharePoint Services [SPTimerV4,DCLoadBalancer14,DCLauncher14,SPWriterV4,SPUserCodeV4,SPTraceV4,SPAdminV4,WebAnalyticsService] and SQL Server services [MSSQLSHAREPOINT,SQLWriter,SQLSERVERAGENT]) services to keep the SharePoint instance live and off course an IIS instance as well; but it seems quite hectic to start\stop such services\software’s on demand as allot of clicks and software switching was required; other big disadvantage was that you have to keep a particular order to start such services else some of the services wont either start or they will eventually fill your event log.We learned that Microsoft did introduce PowerShell to automate such hectic routines, while reading the MSDN and some technical blogs I came to a really good script written by Emmanuel Bergerat which I really love to share as it saved allot of typos for me. To automate the process follow the steps below:

Important: Modify services startup type
You need to modify the startup type of some services; this will not allow the SharePoint instance to start automatically.This step is required once you setup your workstation.
Manual way: Navigate to Control Panel –> Administrative Tools –> Services, locate the following services and change their startup type from automatic to manual save the service setting and close the dialog accordingly.
services
Automate: To keep away from such hassle run the following PowerShell script with administrative privilege's..

# SharePoint 2010 Workstation START up type modification script
'MSSQL$SHAREPOINT',"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 instance script When its required to start the SharePoint 2010 script, run following PowerShell script with administrator privileges.



# Start local SQL Services
"Starting Local SQL Services"
'MSSQL$SHAREPOINT',"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 }
"=> IIS is 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"


Stop SharePoint 2010 instance script To stop SharePoint 2010 instance run following script with administrator privilege's.



# 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
"=> IIS is STOPPED"
" "
# Stop local SQL Services
"Stopping Local SQL Services"
'MSSQL$SHAREPOINT',"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"

No comments:

Post a Comment