Beginning PowerShell Free Tutorial – Creating Your Profile


Whether you’re new to PowerShell or not, when you find yourself ready to start customizing PowerShell and making it do a few tricks, you’re going to want to setup your profile.

Don’t worry, I will show you how to create your profile, and even show you how to add a few cool things to your profile.  You are about to develop the skills to tame that PowerShell profile!


My Profile Was So Confusing When I Started

I knew it was there, but I couldn’t even find where it was supposed to be.  There were some things that I thought I could do with my profile, like:

  • Define a function.
  • Load a snapin.
  • Change the background color of the shell.

But it always seemed like a lower priority than learning some other, more “immediate need”  PowerShell skills.

Once I decided it was time to jump in and customize my profile, I was shocked at the first discovery.

Your PowerShell Profile is not Created by Default

The path to it is there, but you have to create it yourself.  Learning how to create a great PowerShell profile was NOT the hardest thing about learning PowerShell.  But it WAS one of the most frustrating because I knew that it was cool stuff that was just out of my reach.

Find Tech Jobs on Dice!

Here’s how you setup your profile.  First, you can see that the $profile variable is populated, and points to a file.

PS C:\> $profile

But that file doesn’t actually exist

PS C:\> test-path $profile

See? Crazy.  So I need to create the profile.  I use new-item to do this, and use the $profile variable to define where I’m creating the item

PS C:\> new-item $profile -force
Type: file

The “-force” parameter really helps.  It means “create this item and if any part of the directory tree doesn’t already exist then create that too.”  Very nice.  I forgot to add the “-type” for the new-item command, so it prompted me for it.  I left that in there so you can see what it looks like if you forget.  To create it properly, I should have done “new-item $profile -force -type file”.  Either way, we get the result:

Directory: C:\Users\Michael\Documents\WindowsPowerShell

Mode                LastWriteTime     Length Name
—-                ————-     —— —-
-a—         5/27/2010  10:32 PM          0 Microsoft.PowerShell_profile.ps1

The profile has been created!  Since it’s a .ps1 file, we can invoke our default .ps1 editor by using Invoke-Item.

PS C:\> ii $profile

“ii” is an alias for invoke-item.  It means “open the file with the default program”.  Invoke-item on a .txt file or .ps1 and it opens in your default editor – notepad by default, but you should switch to a better text editor, and the sooner the better. 

Invoke-item on an .mp3 will play the .mp3 with the default .mp3 player – Windows Media Player, Winamp, or iTunes, usually.  I use that as a piece of a timer and stopwatch.

That that you have finally created a profile, and opened it,  you can write something simple in it so you know it’s there.

“Hello World.  This is my profile”

Start a new PowerShell session and you’ll see it working.  You’re not done yet, though.

Do the same thing in both the Shell and the ISE.  Two separate shells, two separate profiles. You have to create your profile for each shell that you use, if it doesn’t already exist.

Once you’ve created your profiles, you’re ready to add some cool stuff in there. Here are some customizations you can play with:

What awesome things do you have your profile doing?  Let me know, and if you’ve blogged about it I’ll link over to you.

Find Tech Jobs on Dice!