Getting Started with PowerShell Profiles

Whether you're a beginner at PowerShell, or you're like me, and you've gone years without using a profile, profiles will blow your mind.


So what is a PowerShell profile?

As the name suggests, a PowerShell profile is a set of PowerShell settings specific to you, but it's slightly more than this. A profile is the first script a PowerShell host (console, ISE, etc.) runs when it's launched. More specifically, the host dot-sources the script, making any variables and functions defined in the profile script available to you in your current session. It also runs any code that isn't statically defining a variable, function, class, etc.

What are the advantages of a profile?


One advantage of a profile is that, because it is a file, it can be moved around to multiple machines. So when you use a new computer, it's easy to get PowerShell working YOUR way.


In my opinion, the main advantage of a profile is to increase your productivity by giving you access to the functions and variables you use regularly.


Profiles can also be used to set standards in an enterprise environment, such as creating a transcript of every session or giving you access to enterprise functions and settings.

How do you create a profile?


The path to the profile script is store in the $Profile automatic variable. That being said, there are 4 types of profiles.


$Profile.CurrentUserCurrentHost

This is the default value returned by $Profile. This is the value for you, in this host (the program running PowerShell). The most common hosts people encounter are the PowerShell command line and the PowerShell ISE.


$Profile.AllUsersCurrentHost

Same as the previous one, except this profile applies to all users on the machine. 


$Profile.CurrentUserAllHosts

In this one, this is the profile that will get loaded for the current user, regardless of the host.


$Profile.AllUsersAllHosts

By now, you can probably guess that this one is for all users on the machine, for every host.


To create a profile, you can use either of these two commands:

If you have visual studio code, you don't need to create the file and can just enter:

After this, you can just edit the script the same way you would any other script.



Note: for the AllUsers profile, you need to be an administrator to save the profile.


Koupi allows you to create PowerShell scripts without needing to write a single line of code. Just add the steps you want to perform, fill in the blanks, download the script and run it. It's that easy. Give it a try here (It's free).


Some useful profile functions and examples


Note: I will keep updating this post with more examples over time.


Print text within a box



Replace "||" with a pipe on a new line



Compress a folder using 7Zip


Koupi allows you to create PowerShell scripts without needing to write a single line of code. Just add the steps you want to perform, fill in the blanks, download the script and run it. It's that easy. Give it a try here (It's free).


©2019-2020 by Bulles Technologies. Proudly created with Wix.com