Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

4 Answers

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
3  
-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
add comment

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
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.