cURL to PowerShell
Paste a curl command and get a PowerShell script using Invoke-RestMethod, with quoting that will not eat your API token.
cURL to PowerShell converts entirely in your browser. Commands containing tokens or credentials never leave your device.
Open cURL to C#
cURL to PowerShell के बारे में
Pasting a curl command into PowerShell rarely works, and not only because the flags differ. PowerShell interpolates variables inside double-quoted strings, so a token containing a dollar sign silently becomes an empty string and the request comes back 401 with no clue why. This converter emits single-quoted literals throughout, which PowerShell treats as raw text, and doubles any internal quote. Headers become a hashtable, a JSON body becomes a hashtable piped through ConvertTo-Json so you can edit it before sending, and basic auth is rebuilt as a Base64 Authorization header — the way it has to be done in PowerShell. The result runs as-is on Windows PowerShell and on PowerShell 7 across platforms.
विशेषताएँ
- Invoke-RestMethod with parameters split across readable lines
- Headers emitted as a PowerShell hashtable
- JSON bodies rendered as a hashtable piped to ConvertTo-Json
- Single-quoted literals so $ in a token is never interpolated
- Basic auth rebuilt as a Base64 Authorization header
- Content-Type passed through the -ContentType parameter
- Warnings for curl flags with no PowerShell equivalent
- Download the result as a .ps1 file
- Conversion runs entirely in your browser
cURL to PowerShell का उपयोग कैसे करें
- Copy the curl command from the API documentation
- Paste it into the left pane
- Read the generated PowerShell on the right
- Copy it, or download it as a .ps1 file
उदाहरण
इनपुट
curl https://api.example.com/users -H "X-Api-Key: abc123"
आउटपुट
$headers = @{
'X-Api-Key' = 'abc123'
}
$response = Invoke-RestMethod `
-Uri 'https://api.example.com/users' `
-Method GET `
-Headers $headers
Single quotes keep the value literal, whatever characters the key contains.
सामान्य त्रुटियाँ और समस्या निवारण
- The request returns 401 even though the token is correct. — A double-quoted PowerShell string interpolates anything after a dollar sign, so part of the token disappears. Keep the single quotes this converter emits, or escape the dollar with a backtick.
- The JSON body arrives at the server mangled or with wrong types. — Check the -Depth on ConvertTo-Json. It defaults to 2, which silently flattens nested objects into type names — the generated code sets it to 10 for exactly that reason.
- Non-ASCII characters in the body come out corrupted. — Windows PowerShell 5.1 defaults to a non-UTF-8 encoding on the body. Either move to PowerShell 7, or convert the JSON to UTF-8 bytes and pass those as the body.
अक्सर पूछे जाने वाले प्रश्न
- Is curl the same as Invoke-WebRequest in PowerShell?
- In Windows PowerShell 5.1, curl is an alias for Invoke-WebRequest, which is why pasting a real curl command fails with confusing parameter errors. PowerShell 7 dropped the alias, so curl there is the real thing if it is installed.
- Should I use Invoke-RestMethod or Invoke-WebRequest?
- Invoke-RestMethod for APIs — it parses a JSON response into objects you can work with directly. Invoke-WebRequest returns the raw response with status code and headers, which is what you want when those details matter.
- How do I send basic authentication in PowerShell?
- Base64-encode username:password and pass it as an Authorization header. The -Credential parameter exists but only sends credentials after a challenge, which many APIs never issue.
- Why are the parameters split with backticks?
- The backtick is PowerShell's line continuation character, so a long call stays readable across several lines. It has to be the last character on the line with no trailing space, which is easy to break when editing by hand.
- Will the generated script run on Linux and macOS?
- Yes, on PowerShell 7, which is cross-platform. The cmdlets, hashtable syntax and ConvertTo-Json all behave the same way there as on Windows.
संबंधित टूल
सभी ArrayKit टूल