Jason Turley's Website

How to Create Permanent Powershell Aliases

I started developing on Windows in addition to Linux. I wanted a quick way to open up Visual Studio Code from the command line. The best way I could think of is using a PowerShell alias. Here is how to create a “permanent” PowerShell alias on Windows.

Find Your Profile.ps1 File

PowerShell has a profile.ps1 file that will execute any code inside of it on startup. Similar to vim’s .vimrc runtime config file.

This file can be stored in a few different locations. If you just want your current user to be able to execute the code, then run echo $profile

PS C:> echo $profile
C:\Users\hackerman\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

For all users, add a profile.ps1 script to $PsHome

PS C:> echo $PsHome
C:\Windows\System32\WindowsPowerShell\v1.0

Add Alias

You may need to create the actual profile.ps1 file if it does not exist. Mine didn’t.

Add your alias.

Set-Alias -Name vscode -Value "C:\Users\hackerman\AppData\Local\Programs\Microsoft VS Code\Code.exe"

Restart PowerShell

Restart your PowerShell instance and the changes will take place.

References / Further Reading