curl to PowerShell
Convert curl commands to PowerShell Invoke-WebRequest syntax. Supports headers, POST data, auth, and common flags.
Looks like this contains credentials. They are converted in this tab only — not uploaded, and not included in the link that Share or Copy link produces.
curl to PowerShell Invoke-WebRequest
PowerShell's Invoke-WebRequest (aliased as iwr and wgetin PS) is the equivalent of curl for Windows. Key differences: headers use a hashtable (@{...}), credentials require PSCredential objects, and body data uses -Body. PowerShell 7+ has Invoke-RestMethod (-irm) which automatically parses JSON responses. This converter maps the most common curl flags to their PowerShell equivalents.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Converting an API's curl example into Invoke-WebRequest or Invoke-RestMethod.
- Reproducing a captured request in a PowerShell script.
- Getting the header hashtable and body form right.
- Producing a snippet for a Windows automation task.
- Checking which curl flags have no PowerShell equivalent.
Frequently Asked Questions
- Invoke-RestMethod or Invoke-WebRequest?
- Invoke-RestMethod parses a JSON or XML response into PowerShell objects and gives you only the body — best for APIs. Invoke-WebRequest returns the full response with StatusCode, Headers and RawContent. IRM is the closer match to a typical curl API call.
- Why does curl behave differently in PowerShell?
- In Windows PowerShell 5.1, curl is an ALIAS for Invoke-WebRequest, so curl flags are parsed as PowerShell parameters and fail. PowerShell 6+ removed the alias. Use curl.exe explicitly if you want the real binary.
- How do I send a JSON body?
- -Body ($obj | ConvertTo-Json) -ContentType 'application/json'. Watch ConvertTo-Json's -Depth: it defaults to 2 in Windows PowerShell and silently truncates deeper structures to a type name string.
- How does curl's -k translate?
- -SkipCertificateCheck, but only in PowerShell 6+. On Windows PowerShell 5.1 there is no such parameter and you must override [System.Net.ServicePointManager]::ServerCertificateValidationCallback, which applies process-wide.
- How do I pass basic auth?
- -Authentication Basic -Credential (Get-Credential) in PowerShell 6+. Otherwise build the header yourself: a base64 of user:pass in an Authorization header, which is exactly what curl -u does under the hood.
- What changed between Windows PowerShell 5.1 and PowerShell 7?
- 5.1 parses responses through Internet Explorer's engine unless you pass `-UseBasicParsing`, and has no `-SkipCertificateCheck`. Generated code that runs on 7 can fail on 5.1 for both reasons — the flags are not merely cosmetic.
- Why does the response body sometimes arrive as an object?
- Because `Invoke-RestMethod` deserialises JSON and XML automatically, returning objects rather than text. That is usually what you want, but it means piping to `ConvertFrom-Json` fails — the conversion has already happened.
Common errors and gotchas
- Assuming `curl` in PowerShell is curl, when in older versions it is an alias for Invoke-WebRequest.
- Using Invoke-WebRequest where Invoke-RestMethod is wanted, which parses JSON for you.
- Passing a hashtable body without converting it to JSON, which sends form encoding instead.
- Omitting `-UseBasicParsing` on older versions, which then depends on Internet Explorer being present.
- Expecting a non-2xx to return a response, when PowerShell throws a terminating error instead.