Why PowerShell Profiles?
Each time you open a new PowerShell window, all you loaded modules, created aliases, defined functions and all other configurations will be lost.
You start from scratch each time you open an new window.
With a profile script you have the ability to store modules, custom aliases etc.The only difference about profile script is, it has a special name and location.
Important: If the shell’s execution policy is set to restricted then profile script cannot execute.
Where is the Profile Locations ?
In general , PowerShell will look for the following;
- For current user, $HomeMy DocumentsProfile.ps1
- For all users, $PsHomeProfile.ps1
Note: $Home and $PsHome are predefined constants within the shell. You can type these constants at a command line and press Return to see what paths they contain.
Creating Profile Script
To create a profile script, navigate to $Home path WindowsPowerShell and create a file called profile.ps1
In profile.ps1 just typer commands what you want.Here is an example from my profile.ps1 file.
Now let’s open a new shell session;
What About Security?
Because the profile file is a simple text file and stored in Documents folder, it can be a potential vector for malwares.
In order to secure your profile file, you must run anti-malware software just like to keep secure other files and applications.