Alias in PowerShell

Contents
Get-Alias: existing aliases
Delete alias
Create alias
Configuration
Errors
My aliases
Related articles

Get-Alias

To get a list of existing aliases, you need to run

Get-Alias

CommandType Name Version Source ----------- ---- ------- ------ Alias % -> ForEach-Object Alias ? -> Where-Object Alias ac -> Add-Content Alias asnp -> Add-PSSnapin Alias badalias -> Wrong-Command Alias cat -> Get-Content Alias cd -> Set-Location Alias CFS -> ConvertFrom-String 3.1.0.0 Microsoft.PowerShell.Utility Alias chdir -> Set-Location Alias clc -> Clear-Content Alias clear -> Clear-Host …

There are a lot of standard aliases, here you can see the beginning of the list and one incorrect alias, which we will delete here

Deleting an alias

Starting from version 6 in PowerShell, you can delete aliases with the Remove-Alias command

You can read about how to install PowerShell 7 here

Remove-Alias badalias

In earlier versions, you need to use the Remove-Item command

Remove-Item Alias:badalias

The easiest way to check for alias deletion is to use Select-String

Get-Alias | Select-String -Pattern "badalias"

Creating an alias

You can create an alias with the Set-Alias command

Set-Alias -Name reboot -Value Restart-Computer

If the alias uses a path with spaces, they can be escaped using the character `

Set-Alias -Name app -Value C:\Program` Files\App\app.exe

Configuration

In order for aliases and functions to be saved after a reboot, they need to add to the PowerShell profile settings file

Its location can be found by the command

$profile

C:\Users\Andrei\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

If $profile shows a non-existent path, then the settings file can be created manually.

New-Item -Path $profile -Force -ItemType "file"

The file can then be opened and edited in notepad

notepad $profile

Set-Alias -Name reboot -Value Restart-Computer

PowerShell needs to be restarted.

An example of an alias that runs Python , that is used by TestComplete

Set-Alias -Name tcpython -Value "C:\Program Files (x86)\SmartBear\TestComplete 15\x64\Bin\Extensions\Python\Python310\python.exe"

Errors

Remove-Alias : The term 'Remove-Alias' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + Remove-Alias somealias + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Remove-Alias:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

Remove-Alias has only been supported since the sixth version of PowerShell

Need to update PowerShell or use the Remove-Item command

Remove-Item Alias:somealias

My aliases

Set-Alias -Name firefox -Value C:\Program` Files\Mozilla` Firefox\firefox.exe Set-Alias -Name vi -Value C:\Program` Files\Vim\vim91\vim.exe Set-Alias -Name reboot -Value Restart-Computer Set-Alias -Name tcpython -Value "C:\Program Files (x86)\SmartBear\TestComplete 15\x64\Bin\Extensions\Python\Python310\python.exe"

Article author: Andrei Olegovich

Related articles
Windows
PowerShell
Install
Basics
Alias
Functions
Network
Users
Files
REST API requests
Errors

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: