I can remove an alias like so:
Remove-Item Alias:wget
Then trying the alias gives the expected result:
PS > wget
wget : The term 'wget' is not recognized as the name of a cmdlet, function,
script file, or operable program.
However, if I put the same into a script,
PS > cat wget.ps1
Remove-Item Alias:wget
wget
it gives unexpected result
cmdlet Invoke-WebRequest at command pipeline position 1
Supply values for the following parameters:
Uri:
You need to use unalias command on Linux or Unix to remove bash shell aliases. The alias command used to create aliases. It works on bash, ksh, csh and other Unix shells.
To remove newly created aliases without closing the PowerShell console, you need to use RemoveAlias command. You can also use Del command to remove the alias. Again you cannot remove the Aliases which are permanent. Only newly created aliases can be removed and automatically deleted when the session ends.
Remove aliases For, remove an alias added via command line, you can use the unalias command. Keep in mind that the unalias command also applies only to the current session. To permanently remove one, we must remove the appropriate entry in the ~ / . bash_aliases file.
The following seems to work
If (Test-Path Alias:wget) {Remove-Item Alias:wget}
If (Test-Path Alias:wget) {Remove-Item Alias:wget}
wget
The first line removes the Script
level alias, and the second removes the Global
level alias. Note that both need to be tested, because if the Global
doesn't exist the Script
isn't created.
Also this misbehaves in that it modifies the parent without being dot sourced.
Alternatively you can just dot source your original and that would work
. .\wget.ps1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With