Sharing the experience search

Search sharing-the-experience.blogspot.com

Tuesday, November 29, 2011

Simple concept: How to use SharePoint cmdlets in PowerShell ISE

[Question]:
I heard that I can manage everything in SharePoint 2010 with PowerShell. But when I run Windows PowerShell ISE , it doesn't recognize SharePoint PowerShell commands (ex: Get-SPContentDatabase)

How can I use PowerShell ISE for SharePoint 2010?

[Answer]:
 SharePoint 2010 Management Shell is a just a PowerShell instance that loads sharepoint.ps1 script. So, you are free to use your own favorite IDE to build scripts, just load sharepoint.ps1 (SharePoint 2010: PowerShell and Stsadm)

To get sharepoint.ps1 loaded in PowerShell ISE:

1. Start PowerShell ISE

2. (in case you haven't created a profile yet)
run the following command to create a profile which loads every time you start PowerShell ISE
new-item -path $profile -itemtype file -force 

3. (in case your profile is empty)
the following command writes to profile "." source loading of SharePoint.ps1"

sc  $profile  “.'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\SharePoint.ps1'”

OR use more universal approach which doesn't depend on the SP version (whether it's 14 or 15 (2010 or 2013))

sc  $profile "Add-PSSnapin 'Microsoft.SharePoint.PowerShell'"

4. Restart PowerShell ISE

P.S. In case you don't know where to get PowerShell ISE: PowerShell and SharePoint: What, Why and How

No comments:

Post a Comment