Remove Default PowerShell Aliases
Written on August 10, 2015

PowerShell has a cheeky approach to cross-OS compatibility. Two of my favourite utilities; wget, and curl, are aliased to PowerShell’s Invoke-WebRequest cmdlet. This is nice and all, but Invoke-WebRequest doesn’t work anything at all like curl or wget do, and sometimes I just want to be able to download a file without mucking around with parameters. Even after installing wget.exe and curl.exe into my path, PowerShell grabs ahold of the unqualified names (that is, no extension):

PS C:\> wget
StatusCode        : 200
StatusDescription : OK
Content           : <!doctype html>
                    <!--[if lt IE 7]> <html class="ie7 oldie" lang="en"> <![endif]-->
                    <!--[if IE 8]>    <html class="ie8 oldie" lang="en"> <![endif]-->
                    <!--[if IE 9]>    <html class="ie9 oldie" lang="en">...
RawContent        : HTTP/1.1 200 OK
                    Vary: Accept-Encoding
                    X-Content-Type-Options: nosniff
                    X-XSS-Protection: 1; mode=block
                    Age: 2313
                    Alternate-Protocol: 443:quic,p=1
                    Transfer-Encoding: chunked
                    Accept-Ranges: none

It’s doing this using aliases:

PS C:\> Get-Alias wget,curl | ft -auto
CommandType Name                      Version Source
----------- ----                      ------- ------
Alias       wget -> Invoke-WebRequest
Alias       curl -> Invoke-WebRequest

Enter PowerShell profiles. These are a great way to perform an action at the start of every PowerShell session. Because the aliases for wget and curl are built into PowerShell, we can’t simply disable them system-wide. What needs to occur is a per-session removal of them. Let’s add two commands to my profile that will do this:

"Remove-Item alias:wget; Remove-Item alias:curl" | Out-File $profile -Append -NoClobber

If you receive an error along the lines of “Could not find a part of the path” it probably means your profile doesn’t exist. Create it with the following:

PS C:\> New-Item $profile -ItemType file -Force

After the changes above, we now see this:

PS C:\> wget --no-check-certificate
--2015-08-11 09:32:46--
Resolving ( 2404:6800:4006:800::200e,
Connecting to (|2404:6800:4006:800::200e|:443... connected.
WARNING: cannot verify's certificate, issued by 'CN=Google Internet Authority G2,O=Google Inc,C=US':
  Unable to locally verify the issuer's authority.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: 'index.html'
index.html                        [  <=>                                               ]  10.54K  44.7KB/s   in 0.2s
2015-08-11 09:32:48 (44.7 KB/s) - 'index.html' saved [10793]

Much better!


There's no commenting functionality here. If you'd like to comment, please either mention me (@[email protected]) on Mastodon or email me. I don't have any logging or analytics running on this website, so if you found something useful or interesting it would mean a lot to hear from you.