I sure do a lot of PowerShell scripting lately, and in most cases I develop scripts to interact with SharePoint, meaning I need to load the SharePoint snap-in on every occasion (or use the SharePoint Management Shell instead). One very useful feature of PowerShell is the possibility to set a custom profile for each user, allowing them to specify various pre-configurations that could be set before launching a PowerShell session on a computer. In my case, I tend to always set the PowerShell console’s background to White and have the foreground color to black. I also make sure the SharePoint snapins are always loaded. That’s just the kind of diva I am 🙂
So what is a PowerShell profile anyway? Well, it simply is a .ps1 PowerShell script that you create and that PowerShell will take care of loading before initiating each session. In order to determine where you need to create this profile file, you can simply query PowerShell by typing in the reserved keyword $profile (see Figure below).
Next, all you need to do, is go to the location specified in the PowerShell session, and created the file. In the .ps1 script, simply enter every line of command you wish to see executed at the beginning of every future session. In My case, my profile file looks like the following:
Add-PSSnapin Microsoft.SharePoint.PowerShell
$host.UI.RawUI.BackgroundColor = “White”
$Host.UI.RawUI.ForegroundColor = “Black”
cls
Simply copy my code above, paste it in your profile’s .ps1 file, save the file, and open a new PowerShell session. Your PowerShell window should now look like the following:
Enjoy!