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.
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
C:\Users\Michael\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
But that file doesn’t actually exist
PS C:\> test-path $profile
False
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:
- Add a function to open the support site for Dell computers
- Change the background color on an administrative shell
- Add a daily bible verse to your shell
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.

Looking to learn PowerShell and how to show my path (and convert my dos batch files) Found your site.
I learn best doing “Stare and compare” method. Stare at w means that work and compare at a different means to do the same. Also don’t mind crawling up hill (not too steep) with a little sweat exuded. When hitting a tall wall with no easy means (tools) to get over…… The enthusiasm wanes quickly.
Having said that. I found leaning the path a hard crawl. Until one of the replies showed the ‘$env:path’ example. Whew!
Now I crawled this example ‘Creating your profile’ and did it! But the wall appeared when I wrote something and started a new PS. OOps. No can do. Not “signed”. HuH?. OK ‘The wall’. Permitting my self authorization. Way too many steps (without a comparison (for me)). At this time.
Any escalators (tips, tool etc.)? to get me over “The Wall”?
Oh, as I like my tools (scripts) portable. That is, getting around the ‘Only works (signed) for one computer’. Any clues there also?
Thanks for the ear
Hi Ibeme,
It’s great your starting with PowerShell. Believe me, you will get over the hurdles and it will become second nature. I remember my first weekend with PowerShell in 2007. I spent hours over the 2 days trying to get the number of processor cores and the processor speed from WMI. After 2 days I still couldn’t do it. Now I do stuff like that as simply as typing my name. So stick with it, and be encouraged. Great things await you.
For anyone creating a profile and having trouble with it running, you will need to set your execution policy so that scripts can run.
I’ve outlined that here:
http://www.iLovePowerShell.com/how-to-run-scripts-with-powershell
Michael
Using “$profile” is the same as using “$profile.CurrentUserCurrentHost”, so that’s why you have to set it once for the command line and once for the ISE. Each of those is a separate host.
If you want profile entries to work across hosts, then use “$profile.CurrentUserAllHosts” instead, and you can put entries in that file that will work no matter what host you use.
If you have Admin privileges on the machine, you can also add entries (or create) the profiles for everyone, using “$profile.AllUsersAllHosts” or “$profile.AllUsersCurrentHost”.
Edward
Hi Edward – Thanks for that insight. Nice tip!