Powershell $profile

What’s the purpose of the $profile

The $profile (like a bash script configuration) allows us to configure the way our Powershell command shell looks, or sets the default location, we can add commands and aliases etc.

Where’s the $profile and does it exist?

Typing the following will result in Powershell telling us where the Microsoft.PowerShell_profile.ps1 file is expected to be

$profile

Just because $profile outputs a path, does not mean there’s a file’s there. It’s simply telling us where it goes to get the profile, we may still need to created one, instead we can use the following

We can find out whether a $profile already exists using

Test-Path $profile

Test-Path determines whether all elements of a path exists, i.e. in this case, does the file exist

Creating the profile file

Typing

New-Item -path $profile -itemType file -force

will create a new item (in this case a file) at the location (and name) supplied by the $profile variable. The force switch ensure the file is overwritten if it already exists.

The ps1 file is just a text file, so from the command line you can run Notepad or powershell_ise (or ofcourse from the Windows GUI you can do the same) and edit the file, allow us to enter the commands that might want available from session to session.