Convert curl to PowerShell
Convert curl commands to PowerShell code using Invoke-RestMethod. curl2code runs entirely in your browser via WebAssembly — your data stays private. For C#, try our curl to C# converter. For Python, see curl to Python. Below are ready-to-use PowerShell examples.
How to copy curl from your browser
- 1
Open DevTools
Press F12 or Ctrl+Shift+I to open your browser developer tools.
- 2
Go to the Network tab
Click the Network tab and perform the action that triggers the HTTP request.
- 3
Copy as cURL
Right-click the request → Copy → Copy as cURL. Then paste it above.
Frequently Asked Questions
What is PowerShell Invoke-RestMethod?
Invoke-RestMethod is PowerShell's built-in cmdlet for making HTTP requests with automatic JSON/XML parsing. It returns parsed objects directly — no manual deserialization needed. Available in PowerShell 3.0+ and PowerShell Core. curl2code also supports Invoke-WebRequest which returns the raw response.
Invoke-RestMethod vs Invoke-WebRequest — which to use?
Invoke-RestMethod automatically parses JSON/XML responses into PowerShell objects — ideal for API work. Invoke-WebRequest returns the full response with headers, status code, and raw content — better for debugging and non-JSON responses. Use RestMethod for APIs, WebRequest for scraping or diagnostics. For a similar .NET approach, see curl to C#.
How to handle authentication in PowerShell?
For Bearer: Invoke-RestMethod -Uri $url -Headers @{ Authorization = "Bearer $token" }. For Basic auth, use -Credential (Get-Credential) or -Authentication Basic (PowerShell 6+). PowerShell securely handles credentials with SecureString. curl2code converts auth flags to PowerShell cmdlet parameters.
How to send multipart form data in PowerShell?
PowerShell 6+ supports -Form @{ file = Get-Item "doc.pdf"; desc = "My file" } for multipart uploads. In Windows PowerShell 5.1, construct the multipart body manually or use .NET classes (System.Net.Http.MultipartFormDataContent). curl2code handles -F flag conversion.
How to handle HTTP errors in PowerShell?
Use try/catch: both cmdlets throw WebException on non-2xx responses. Access the response with $_.Exception.Response. In PowerShell 7+, use -SkipHttpErrorCheck to prevent throwing and check $response.StatusCode manually instead.
How to work with JSON in PowerShell?
Invoke-RestMethod parses JSON automatically into PSObject. For manual conversion: $data = $json | ConvertFrom-Json. To send JSON: $body = @{ name = "John" } | ConvertTo-Json. PowerShell's object pipeline integrates naturally with parsed API responses for filtering and transformation.
How to set timeouts in PowerShell?
Use -TimeoutSec 30 parameter on both cmdlets. In PowerShell 7+, use -ConnectionTimeoutSeconds and -OperationTimeoutSeconds for fine-grained control. For retries, use -MaximumRetryCount 3 and -RetryIntervalSec 2 (PowerShell 7.1+).
How to use a proxy in PowerShell?
Use -Proxy 'http://proxy:8080' parameter. For proxy auth: -ProxyCredential (Get-Credential). PowerShell respects system-wide proxy settings by default on Windows. To bypass: -NoProxy (PowerShell 6+). curl2code converts -x flags to PowerShell proxy parameters.
How to send a POST request with JSON body in PowerShell?
Convert a curl POST command like curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL to PowerShell using curl2code. The generated code uses Invoke-RestMethod -Uri $url -Method Post -Body ($data | ConvertTo-Json) -ContentType 'application/json'. curl2code automatically detects -d/--data flags with JSON content and sets the appropriate Content-Type header in the Invoke-RestMethod code.
How to add Bearer token authorization in PowerShell?
Pass curl -H "Authorization: Bearer YOUR_TOKEN" URL to curl2code and it generates Invoke-RestMethod code with the auth header: -Headers @{ Authorization = 'Bearer YOUR_TOKEN' }. curl2code detects Bearer tokens from both -H "Authorization: Bearer ..." and --oauth2-bearer flags. For Basic auth, use -u user:pass.
How to set Content-Type header in PowerShell?
curl2code converts curl -H "Content-Type: application/json" URL to Invoke-RestMethod code with the proper header: -ContentType 'application/json'. For -d data, curl defaults to application/x-www-form-urlencoded; for -F form uploads, it uses multipart/form-data. curl2code maps each to the correct Invoke-RestMethod API.