For some unknown reason, the devs included "curl" as an alias for Invoke-WebRequest, even though it is not compatible with the proper implementation of curl, which means it gets in the way when I try to make a curl request. I can remove the alias using Remove-Item alias:curl, but next time I start Powershell, the alias has returned. Is there a way to remove it permanently without having to run a script every time I start?
- 1,546
5 Answers
Skip this step if you already have a Powershell profile:
New-Item $profile -force -itemtype file
Then edit your profile:
notepad $profile
Add the following line to it:
remove-item alias:curl
Save, close notepad and reload the profile with the command below or close and open Powershell to apply the profile:
. $profile
- 2,404
-
3Thanks. I must say it's annoying that the powershell developers didn't think this through, forcing us to now have to work around the issue in this way. – Nathan Ridley Mar 17 '15 at 02:12
-
I don't think it's meant to be a 1:1 replacement. Powershell focuses on an overarching use of a defined set of parameters and automatic parameter binding (which is really great once you get into it). Providing the curl alias is to show folks accustomed to *nix that there is a curl equivalent in Powershell. – megamorf Mar 17 '15 at 07:32
-
2The first step can always be skipped. I just did, and got a pop-up asking if I wanted to create the file. – Niko Fohr Aug 23 '17 at 17:12
-
-
The "funny" thing is that even azure docs show curl commands to quickly test out thing. Real curl commands, not
Invoke-WebRequestsyntax... – Akos Lukacs Oct 04 '18 at 12:53 -
For people who googled this and want to remove their individual aliases: If I remove the alias from $profile, close the session and open it, it should be blown away without using remove-item. Or instead of closing $profile, sourcing it. – Timo Oct 22 '20 at 15:52
I'd stick with using curl.exe instead of just curl. This approach doesn't rely on PowerShell running with particular profile (and PowerShell could be run with no profile at all using -NoProfile switch).
- 2,652
-
1I could argue that in theory, powershell may eventually run on unix, where program files don't have a ".exe" extension. It makes absolutely no sense to unix people to have aliases enabled in scripts. I have to wonder whether that bad-design choice was deliberate to try to kill the opensource GNU software stack on windows. And why don't we at least have a "command" built-in to force the shell to look for a real program? Powershell really fails on the KISS principle. – Johan Boulé Jan 16 '18 at 10:23
-
1@JohanBoulé No need for for conspiracy theories, it was just an oversight. PowerShell 6 already runs on Linux and the alias issues are partially fixed. See this links: initialsession: remove curl and wget aliases, Please remove all built-in aliases and put them in a module, Provide a syntax to call native binaries when its name is aliased – beatcracker Jan 16 '18 at 14:26
-
Is there a way to remove it permanently without having to run a script every time I start?
Technically, no. However, you can utilize the built-in PowerShell Profiles, which runs a script every time you load up PowerShell, to do it for you. But, at least it's not manual.
This is (part) of what I added to my $profile.AllUsersAllHosts file. It is similar to megamorf's answer but slightly more expansive.
Remove-Item alias:curl
Set-Alias curl "${env:SystemRoot}\System32\curl.exe"
Set-Alias wcurl Invoke-WebRequest
You can do this with any of the 6 Powershell profile files, but I'm the only one who uses my desktop, and I see no harm in changing it up a little. If you're not, then go with a different one with a smaller scope. The default $Profile is CurrentUserCurrentHost, so that can't hurt, I'll do the rest of it with that in mind, just substitute the code for whichever one you're changing.
Open a PowerShell terminal, as an Administrator if you can, but I'm fairly certain that the default, CurrentUSerCurrentHost, does not require admin privileges.
Then run:
if (!(Test-Path -Path $profile.currentusercurrenthost)) {
New-Item -ItemType File -Path $profile.currentusercurrenthost -Force
}
Then run notepad $profile.currentusercurrenthost
That will check to see if the file exists, if it does not, it will create the file. Then the second command will then open it with notepad.
Note: If you have VSCode or Notepad++ installed, you can open it with VSCode by typing code $profile.currentusercurrenthost instead of notepad. For notepad++ run the command Set-Alias npp "${Env:ProgramFiles}\Notepad++\notepad++.exe" to temporarily create an alias for Notepad++. That way, you can simply type npp $profile.currentusercurrenthost, and it'll open in notepad++. It's similar with other file editors. You can also add this to your profile as well if you'd like that to be permanent.
Then add the lines as you see fit, though this first one must be first.
Remove-Item alias:curl will simply remove the existing alias curl has for Invoke-WebRequest every time you open a powershell prompt.
Set-Alias curl "${env:SystemRoot}\System32\curl.exe" sets curl to be an alias for curl.exe which is the actual cURL. It's included in Windows 10 Build 17063 and later.
I also chose to add an alias for the original Invoke-WebRequest, calling it wcurl, with Set-Alias wcurl Invoke-WebRequest as there may be situations when I want to use it, and don't want to type out the long string there.
So, in order, that is:
Remove-Item alias:curlSet-Alias curl "${env:SystemRoot}\System32\curl.exe"Set-Alias wcurl Invoke-WebRequestSet-Alias npp "${Env:ProgramFiles}\Notepad++\notepad++.exe"
Everything after #1 is optional, and the order after #1 does not matter, but #1 must be before #2, or any attempts to create an alias named curl.
If this is a brand new profile, it will be blank upon opening it, and you can add them (in order) if you want them or not. If it's not blank, I would recommend adding it towards the end, if not the end. Personally, my $Profile ends with
cls
pwsh -v
which clears the screen from the various operations it does upon boot, and shows the PowerShell version.
- 31
Just add this to your powershell profile:
notepad $profile
if(Test-Path -Path alias:curl) { Remove-Item alias:curl }
Windows Powershell has this default curl alias, but Powershell Core doesn't.
If you want your profile useable for both, you should add Test-Path before remove.
- 160
add Remove-Item alias:cur to powershell autorun script
above XP,2003:
%ALLUSERSPROFILE%\Documents\Msh\profile.msh
%ALLUSERSPROFILE%\Documents\Msh\Microsoft.Management.Automation.msh_profile.msh
XP,2003:
%USERPROFILE%\My Documents\msh\profile.msh
%USERPROFILE%\My Documents\msh\Microsoft.Management.Automation.msh_profile.msh
- 6,775
Remove-Item alias:curlinside windows server 2019 and it's does not appear again even after restaring – mati kepa Feb 21 '19 at 10:38