Load SharePoint Snapin to PowerShell ISE by Default

Problem:  If you use the PowerShell ISE to edit your SharePoint-PowerShell scripts, you may notice that SharePoint cmdlets are not available by default until you explicitly load them with the “Add-PSSnapin” cmdlet. This is because the ISE doesn’t load SharePoint PowerShell Snap-ins by default.

Solution: Here is the nifty trick to load SharePoint snap-in in PowerShell ISE by default! All you have to do is: Add the SharePoint snap-in to your PowerShell ISE profile file, which is getting executed each time you fire PowerShell ISE! Here is how:

To make sure that the profile file is created, run:

#Check if the profile file exists already  
if (test-path $profile)
{
    write-host "profile file already exists at: $profile"
}
else
{
    #Create the profile file
    New-Item -type file -path $profile -force
    write-host "profile file has been created!"
}

This script will create a new profile file if it isn’t created already! Your output will be something like this:

add sharepoint snapin to powershell ise

Open the profile file you received from the above script and add the below line. (in my case, its: C:\Users\salaudeen\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1), save and close.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

So, from now on, you don’t need to explicitly load SharePoint PowerShell snapins as your first line of script! This will definitely save your time and enhance your scripting experience. To make this change for all users, use: $profile.AllUsersAllHosts instead of $profile in the above script.

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *