Introduction
We all know PowerShell is a very powerful scripting tool and SharePoint administration jobs are completely dependent on this. Windows PowerShell has an ISE (Integrated Scripting Environment) which helps administrator or developer to perform lots of command liners or tasks through this and can debug.
Background
How to use SharePoint Commandlets in PowerShell ISE? We are already aware of SharePoint YYYY Management Shell and that works as a command liner for us. Most of us are from a development background and have a very pleasant feel of working with Visual Studio IDE and suddenly we are asked to work on the command liner which makes our life a little sad. So, here is the solution - PowerShell ISE. But, when you start PowerShell ISE, you cannot directly execute the SharePoint Commandlets. So, this tip is all about running SharePoint Commandlets on PowerShell ISE.
Using the Code
Here are the steps to make PowerShell ISE work for SharePoint Commandlets.
- Go to Start -> All Programs -> Accessories -> Windows PowerShell -> Windows PowerShell ISE
- Execute the below command. After execution, shell will create the folder and inside that, it will create a new PowerShell file.
- Go to Computer -> Libraries ->Documents
- Open WindowsPowerShell folder and you will see Microsoft.PowerShellISE_profile.ps1. Open it in Windows PowerShell ISE.
- Execute the below command and save it.
- Restart the Windows PowerShell ISE.
- You are ready. Happy scripting.
Points of Interest
I know we are so lazy that we want to get everything as easy as Copy & Paste. So, all the scripts images above are in text format.
- Script snippet for Step 2.
if (!(test-path $profile ))
{
new-item -type file -path $profile -force
}
- Script Snippet for Step 5.
if((Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null)
{
Add-PSSnapIn "Microsoft.SharePoint.Powershell"
}
- If you receive any access issue while executing the above script snippet, refer to this link.
Solution:
Set-ExecutionPolicy Unrestricted
- The above example will create a file for your logged in profile in Windows system. If you want to make it work for all users and you have administrator access, then you can use the below command. It will create a profile.ps1 file at "C:\Windows\System32\WindowsPowerShell\v1.0" folder. After executing the below script, follow Step 5 to Step 6.
if (!(test-path $profile.AllUsersAllHosts))
{
new-item -type file -path $profile.AllUsersAllHosts-force
}
History
- 22nd December, 2015: Initial post