- SharePoint or your customized snap-in do not load automatically when you start PowerShell ISE. You have to add those manually every time when you have new instance.
- There are several places you could add the PowerShell profile to add SharePoint 2010 and your own cmdlets automatically. However the scope and location of those scripts are different and difficult to remember when there is an issue.
Before you setup this on SharePoint side, you should understand the scope of the profile for Powershell. Here is the location you could setup the profile that will automatic adding SharePoint 2010 and your own cmdlets to PowerShell ISE. The profiles ate listed in precedence order and the first profile has the highest precedence.
Description Path ----------- ---- Current User, Current Host $Home\[My ]Documents\WindowsPowerShell\Profile.ps1 Current User, All Hosts $Home\[My ]Documents\Profile.ps1 All Users, Current Host $PsHome\Microsoft.PowerShell_profile.ps1 All Users, All Hosts $PsHome\Profile.ps1
Here are the profile locations for my SharePoint server.
- C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
- C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\profile.ps1
Open Powershell ISE from Programs->Accessories->PowerShell folder
a. Run the following code from the immediate window in ISE to create a new profile for all users on all hosts. You could change it easily based on the different syntax to create the profile. You should change the other variables in the other commands accordingly.
if (!(test-path $profile.AllUsersAllHosts))
{new-item -type file -path $profile.AllUsersAllHosts-force}
b. Run the following code to edit the new profile
psEdit $profile.AllUsersAllHosts
C. When profile1.ps1 opens, add the following code to attach the SharePoint snap-in every time PowerShell is run.
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }
{ Add-PSSnapIn QualcommCMDLETs } /* this is customized cmdlets */
d. Save profile.ps1 and close PowerShell ISE.
e. You should see the following file craeted C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
f. Start PowerShell ISE again and type the following command to verify that the SharePoint snap-in loaded. You should see SharePoint-specific command listed.
Get-Command Get-SP*
You may noticed one warning if you launch the SharePoint 2010 Management Shell from Programs->Microsoft SharePoint 2010 Products->SharePoint 2010 Management Shell indicates some snap-in already added. This is because SharePoint 2010 Management Shell already added the SharePoint snap-in already. You could ignore this warning message and enjoy the PowerShell ISE with all the SharePoint commends and your own cmdlits from now.
No comments:
Post a Comment