GOAL: Identify and create your PowerShell profile file, define an alias for a command, and put that alias definition in your profile so that it persists across PowerShell sessions.
If you're familiar with Unix, you are probably familiar with the idea of a profile file - a script that executes every time you open a terminal window or log in to the system. Windows PowerShell implements this functionality, and you can locate and edit your profile to automate environmental and setup tasks.
To see where your profile file is located, just print out the value of the $profile variable:
$profileOn my machine, this is the result:
C:\Users\{me}\Documents\Windows\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
You can see that this file doesn't actually exist (yet) with the test-path command:
test-path $profileThe test-path command returns False if the file doesn't exist.
You can set an alias for a PowerShell command. Let's try a trivial example:
Set-Alias boing dirNow, you can type boing and get a directory listing - but only for the current PowerShell session. Handy, but cumbersome if you want to use boing to get a directory listing in future PowerShell sessions.
If your profile file does not exist, you can create it this way:
New-Item -Path $profile -ItemType file -ForceOnce the file has been created, editing it in Notepad is easy:
notepad $pathAdd the Set-Alias command to your profile script:
Set-Alias boing dirSave the profile file and exit Notepad.
Exit Powershell and start it up again - your boing alias should give you a directory listing. Naturally, you can add other PowerShell commands to your profile script at any time, and they'll be executed every time you start PowerShell.
By working through these steps, you've learned a number of things: