Custom Session Configuration for Managing SharePoint 2010 with PowerShell Remotely

by Sergey ZelenovNo presence information on 5/5/2011 2:23 PM

Category: Administration; PowerShell

​This here is something that I’ve been meaning to blog about for quite some time – as I just couldn’t find this information anywhere on the Web. There are quite a few good – fairly detailed and practical – blog posts on configuring PowerShell remoting for SharePoint administration, like this one and this one, but none of them ever mention custom session configurations…

However, this seems to be about the only way to configure remote sessions to use the ReuseThread option for the threading model, which is really important for effective memory management wherever SharePoint is involved.

So, for any SharePoint server that allows remote PowerShell connections, I would recommend creating a custom session configuration with something like the following:

PS > Register-PSSessionConfiguration -Name SharePoint -ThreadOptions ReuseThread
-StartupScript “$env:CommonProgramFiles\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\SharePoint.ps1”

Of course, instead of using SharePoint’s OOB script as startup script, you can use your own custom one – which can do lots of other useful things, such as define your functions and aliases, load other assemblies, snap-ins or modules, dot-source your scripts, etc.

To make use of the newly created configuration, just supply its name as value for the -ConfigurationName parameter of the New-PSSession, Enter-PSSession or Invoke-Command cmdlet:

PS > Enter-PSSession -ComputerName SERVER01 -Credential CONTOSO\Administrator
-Authentication CredSSP -ConfigurationName SharePoint

Advertisements