Tuesday, February 1, 2011

Powershell scripts for Sharepoint 2010/ 2013

To stop a Sharepoint service on basis of GUID

Stop-SPServiceInstance {GUID}

 -------------------------------------------------------------------------------------------------------------------------------------------------------------------
To Start a Sharepoint service on basis of GUID

Start-SPServiceInstance {GUID}

 -------------------------------------------------------------------------------------------------------------------------------------------------------------------
To Start a Sharepoint service on basis of name

Get-SPServiceInstance | Where-Object {$_.TypeName –eq ‘Central Administration/User profile Synchronization service’} | Start-SPServiceInstance

 -------------------------------------------------------------------------------------------------------------------------------------------------------------------
To Stop a SharePoint Service

Get-SPServiceInstance | Where-Object {$_.TypeName –eq ‘Central Administration/User profile Synchronization service’} | Stop-SPServiceInstance

 -------------------------------------------------------------------------------------------------------------------------------------------------------------------
To Stop service on particular server

Get-SPServiceInstance -Server "ServerName"  | where-object {$_.TypeName -eq "User Profile Synchronization Service " } | Stop-SPServiceInstance -Confirm:$false

 -------------------------------------------------------------------------------------------------------------------------------------------------------------------
To Start service on particular server

Get-SPServiceInstance -Server "ServerName"  | where-object {$_.TypeName -eq "User Profile Synchronization Service " } | Start-SPServiceInstance -Confirm:$false

 -------------------------------------------------------------------------------------------------------------------------------------------------------------------
Update Distributed cache Size

Update-SPDistributedCacheSize -CacheSizeInMB CacheSize

 ------------------------------------------------------------------------------------------------------------------------------------------------------------------
Export/Import of subsite

Export-SPWeb "http://SiteCollection/sites/Site1/Subsite1" -Path "C:\Export.cmp"
Import-SPWeb "http://SiteCollection/sites/Site1/Subsite2" -Path "C:\Export.cmp"

 ------------------------------------------------------------------------------------------------------------------------------------------------------------------
Export/Import of list

Export-SPWeb “http://abc.com/site/” –ItemUrl “Lists/employee” –Path “c:\export\employee.cmp”
Import-SPWeb “http://abcxyz.com/site/” -Path "c:\export\employee.cmp"

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Activate Publishing features through powershell


Enable-SPFeature -Identity PublishingSite -URL https://abc.com -Force
Enable-SPFeature -Identity PublishingWeb -URL https://abc.com -Force


-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Session state for SharePoint 2013
New-SPStateServiceDatabase -Name "SP2013_Env_StateService" | New-SPStateServiceApplication -Name "State Service Application" | New-SPStateServiceApplicationProxy -DefaultProxyGroup


Enable-SPSessionStateService -DatabaseName SP2013_Env_ASP_NET_SPSessionStateService -DatabaseServer SP2013_Env_ALIAS_Servername


More reading at
http://nikpatel.net/2012/02/12/enable-asp-net-session-state-on-sharepoint-2010-application/
http://blogs.msdn.com/b/markarend/archive/2010/05/27/using-session-state-in-sharepoint-2010.aspx