Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

PowerShell: Profile Script

📅 2011-Jul-30 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ powershell ⬩ 📚 Archive

The profile script is a text file that is executed whenever an instance of PowerShell is created. This is similar to the bashrc file for the bash shell. The user can store the commands in this file that he wants to be executed whenever PowerShell starts up.

Profile Script for Default PowerShell Console

To find out the filename and path of the profile script for you, type:


The profile script is typically a file named Microsoft.PowerShell_profile.ps1 and its location is C:\Users\AverageJoe\Documents\WindowsPowerShell

This directory and this profile script file is not created by default. If you want to add some startup commands, you will need to create the WindowsPowerShell directory and a text file named Microsoft.PowerShell_profile.ps1 within it to store your commands.

Note: You might have to change the execution policy to allow unsigned scripts to be executed. To find out more on this go here.

Profile Script for Other PowerShell Consoles and Users

PowerShell can be hosted by other console or terminal programs or can be executed by other users. The profile script path for such situations is different. To find out the profile script paths for all these cases, type:

$profile | Format-List -force

The output of this command will have entries for AllUsersAllHosts, AllUsersCurrentHost, CurrentUserAllHosts and CurrentUserCurrentHost. Host is the PowerShell jargon for a console or terminal that executes PowerShell. So, for example if I run PowerShell using a different console, but with the same username, I would place my startup settings in the file given by CurrentUserAllHosts.

(A hat tip to Boe Prox for pointing out this useful command! 😊 )

Tried with: PowerShell 2.0