SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing in Sharepoint and I like more Windows Powershell than Sharepoint Management Shell. Every time I restart the development machine, I have to run Add-PSSnapin Microsoft.Sharepoint.Powershell in order to use Sharepoint cmd-lets.

How to get the machine to automatically load Sharepoint snapin when I start Windows Powershell.

share|improve this question
up vote 10 down vote accepted

In your PowerShell shell type

Notepad $PROFILE

This will give you the scripts that is triggered for the user that is logged in.

If your profile is not created, then you can create it with this command:

new-item $profile -type file -force

here you can insert scripts that are executed before startup.

Here you can add SharePoint snapin:

Add-PsSnapin Microsoft.SharePoint.PowerShell -EA 0

I usually here set stuff like

Set-Strictmode -Version Latest
$host.UI.RawUI.WindowTitle = "$env:UserName | $env:Computername"
[Environment]::CurrentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath
share|improve this answer
rask: what is this wonderful -EA 0 parameter, undocumented ? – Steve B Jun 23 '11 at 12:22
-ErrorAction SilentlyContinue so it doesnt throw an error if module is loaded. Note that this will actually throw an error in SharePoint shell, since SharePoint doesnt check if module is already loaded :-( – Anders Rask Jun 23 '11 at 12:34
rask: it can be usefull in .ps1 file, as I can add the snapin in the head of the file, and run the ps1 either from a naked powershell console, or a sharepoint powershell console. – Steve B Jun 23 '11 at 12:41
When I run notepad $profile it says: The system cannot find the path specified. So I created this file manually and added Add-PsSnapin Microsoft.SharePoint.PowerShell -EA 0. Thank you for your answer! – Anatoly Mironov Jun 23 '11 at 14:08
yep, if its not created you just save it. Glad to be of help. – Anders Rask Jun 23 '11 at 14:12

If you're running Sharepoint 2010, use the SharePoint 2010 Management Shell located at:

Start | All Programs | Microsoft SharePoint 2010 Products | SharePoint 2010 Management Shell

This starts PowerShell and loads the SharePoint cmdlets. You'll probably want to Shift-Right Click this item and select "Run as administrator" from the context menu.

Note that this shortcut is only available on the SharePoint server or on a development workstation where SharePoint is installed locally.

share|improve this answer
Yes, you are right. But I like Windows Powershell GUI more. – Anatoly Mironov Jun 23 '11 at 14:32

If you create a shortcut with the following command line, you'll get the snapin installed:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit add-pssnapin microsoft.sharepoint.powershell

(Obtained from TechNet)

share|improve this answer
It works. But is there is a possibility to add it to profile ps1 or something so one doesn't need to create custom shortcuts? I like the pinned shortcut on the panel. – Anatoly Mironov Jun 23 '11 at 11:20

Another related option is to set the value not just for the logged in user, but for all users on the device. This can be done with

notepad $PROFILE.AllUsersAllHosts

Any code you add in here will be run for all users. For example, adding this will automatically load the SharePoint snapin

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }
share|improve this answer

This solution is one PowerShell script that will create the AllUsersAllHosts file if necessary and then append the Add-PSSnapIn command and then restart PowerShell or ISE and is based on this and this.

if (!(test-path $profile.AllUsersAllHosts)){
    new-item -type file -path $profile.AllUsersAllHosts –force

$cmd = 'if((Get-PSSnapin | Where-Object {$_.Name -eq
"Microsoft.SharePoint.PowerShell"}) -eq $null) 
    Add-PSSnapIn "Microsoft.SharePoint.Powershell" 

out-file -FilePath $profile.AllUsersAllHosts -InputObject $cmd -Append

# based on


$proc = Get-Process -Id $PID
$cmdArgs = [Environment]::GetCommandLineArgs() | Select-Object -Skip 1

$params = @{ FilePath = $proc.Path }
if ($AsAdministrator) { $params.Verb = 'runas' }
if ($cmdArgs) { $params.ArgumentList = $cmdArgs }

if ($Force -or $PSCmdlet.ShouldProcess($proc.Name,"Restart the console"))
    if ($host.Name -eq 'Windows PowerShell ISE Host' -and $psISE.PowerShellTabs.Files.IsSaved -contains $false)
        if ($Force -or $PSCmdlet.ShouldProcess('Unsaved work detected?','Unsaved work detected. Save changes?','Confirm'))
            foreach ($IseTab in $psISE.PowerShellTabs)
                $IseTab.Files | ForEach-Object {

                    if ($_.IsUntitled -and !$_.IsSaved)
            foreach ($IseTab in $psISE.PowerShellTabs)
                $unsavedFiles = $IseTab.Files | Where-Object IsSaved -eq $false
                $unsavedFiles | ForEach-Object {$IseTab.Files.Remove($_,$true)}

    Start-Process @params
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.