What are PowerShell Profiles?

Simply put, a PowerShell profile is a script that runs when I load an instance of PowerShell. I favor having nice little messages each time I load PowerShell, especially when they’re in the flavor of Futurama.

After all, who doesn’t want a fancy message when they start PowerShell?!

Creating Profiles in PowerShell

Great! I’m sold on profiles. Let’s get a profile made and get the magic started.

I can find out where my default profile is stored by typing $profile inside PowerShell. It is one of the built-in automatic variables (See help for more info on automatic variables).

$profile

By default, this file doesn’t exist. So, I’m going to need to create the file before I can add any code to it.

New-Item $profile -ItemType File -Force

Now that my profile is created, I can easily edit it with my preferred text editor. For simplicity, I’m going to use notepad.

Running the following will open up that file via notepad.

Notepad $profile

Using PowerShell Profiles

Let’s put some code into it and see what happens. I’m a fan of random quotes, so I’ll add a nice thought about procrastination to my $profile.

Closing and reopening PowerShell should kick off that extra code.

As a result, every time that I start PowerShell, my motivation will skyrocket to new heights… or something! I’ll figure it out later.

NOTE: Profiles are simply PowerShell scripts (.ps1 files) that run when PowerShell starts up, so the execution policy will be applied. If I have a restrictive execution policy, I will end up with an error when I start up my PowerShell console.

In any case, that’s really all there is to create my $profile in PowerShell and kicking off some code at the beginning.

But Wait, There’s More (Profiles)

Order now and you’ll get not one, but six (or more) profiles with your standard PowerShell! We’ll even throw in free shipping!

In addition to the two sets of profiles per host application, I have two profiles defined for all hosts.

AllUsersAllHosts

C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1

CurrentUserAllHosts

C:\Users\kris.powell\Documents\WindowsPowerShell\profile.ps1

This makes for 6 total profiles with just regular PowerShell and PowerShell ISE. In my case, I also have Visual Studio Code installed, so I have 8 total profiles to work with!

I can find more info about the current application host with the Get-Host cmdlet or the $host built-in variable.
Be sure to check out my upcoming blog about PowerShell hosts. I’ll get into more detail there.

Wrapping Up

Now I feel like I know everything about PowerShell profiles but had been afraid to ask. Yay!