PowerShell Profiles

If you use the PowerShell prompt a lot and/or the PowerShell ISE, you might find your life made a little bit easier by setting up a PowerShell Profile.

All they are is a script that’s run each time you open the powershell.exe prompt or the powershell_ise.exe ISE (or both). You can put anything you like in them, e.g. adding the VMware PowerCLI snapins, setting the current folder, whatever. Note that $profile points to different files for the prompt vs the ISE.

The file is referenced via the built in variable $profile, which actually has several different options depending on whether you want the profile script to run for the PowerShell prompt, the ISE, both, the current user, any user on the PC, etc. Personally, I find the most useful one is the CurrentUserAllHosts, which means it runs for both the prompt and the ISE.

The WindowsPowerShell folder doesn’t exist, but we can create that and an empty profile script with New-Item:

New-Item -Path $profile.CurrentUserAllHosts -ItemType File -Force

If you’re in the ISE, you can then edit your new profile script by using:

psedit $profile.CurrentUserAllHosts

You might like to create a “Scripts” folder in your user profile, and then use the profile to set that as a PSDrive and change to it:

New-PSDrive -Name Scripts -PSProvider FileSystem -Root $env:USERPROFILE\Scripts
Set-Location -Path Scripts:\

Obviously, depending on what you put in your $profile it might delay your PowerShell startup experience somewhat.


This entry was posted in PowerShell and tagged , , , , , , , , . Bookmark the permalink.

One Response to PowerShell Profiles

  1. Pingback: Get Uptime with Get-Uptime | Robin CM's IT Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.