https://github.com/ThePoShWolf/Curl2PS
PowerShell module for converting Curl commands to PowerShell
https://github.com/ThePoShWolf/Curl2PS
Last synced: 4 months ago
JSON representation
PowerShell module for converting Curl commands to PowerShell
- Host: GitHub
- URL: https://github.com/ThePoShWolf/Curl2PS
- Owner: ThePoShWolf
- License: mit
- Created: 2019-03-07T20:50:03.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2024-04-11T01:09:30.000Z (about 1 year ago)
- Last Synced: 2024-08-13T07:05:17.525Z (8 months ago)
- Language: PowerShell
- Size: 2.64 MB
- Stars: 96
- Watchers: 7
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - ThePoShWolf/Curl2PS - PowerShell module for converting Curl commands to PowerShell (PowerShell)
README
# Curl2PS
[](https://www.powershellgallery.com/packages/Curl2PS/)
This module is a utility module to help convert curl commands to Invoke-RestMethod syntax.
This module includes classes for dealing with the curl command as well as URLs, but primarily converts curl commands to Invoke-RestMethod syntax with the ```ConvertTo-IRM``` function.
To install the module:
```powershell
Install-Module Curl2PS
```Usage examples:
```powershell
$CurlString = @"
curl -H "X-Auth-Key: 61e5f04ca1794253ed17e6bb986c1702" -H "X-Auth-Workspace: [email protected]" -H "X-Auth-Signature: " -H "Content-Type: application/json" -H "Accept: application/json" -X GET https://us1.pdfgeneratorapi.com/api/v3/templates
"@PS> $splat = ConvertTo-IRM $CurlString
PS> Invoke-RestMethod @splat
```Or if you'd prefer the string command:
```powershell
ConvertTo-IRM $CurlString -CommandAsStringInvoke-RestMethod -Uri https://us1.pdfgeneratorapi.com/api/v3/templates -Method GET -Headers @{
'X-Auth-Key' = '61e5f04ca1794253ed17e6bb986c1702'
'Accept' = 'application/json'
'X-Auth-Signature' = ''
'X-Auth-Workspace' = '[email protected]'
'Content-Type' = 'application/json'
}
```Or another example:
```powershell
PS> ConvertTo-IRM -CurlCommand 'curl --request GET "https://ncg1in-8d1rag:[email protected]/tickets?status=open,onhold&role=user&limit=6&format=json" --data ""' -CommandAsStringInvoke-RestMethod -Uri https://api.sherpadesk.com/tickets -Method GET -Headers @{
'Authorization' = 'Basic bmNnMWluLThkMXJhZzo1bnVhdXpqNXBrZmZ0bHozZm15a3NteWhhdDZqMzVrZg=='
}
```## Issues
If you find a curl command that doesn't properly convert, please [open an issue](./../../issues)!
PRs welcome!
## Change log
### 0.1.2
- Now supports commands that use `curl.exe`. (thank you [@ImportTaste](https://github.com/ImportTaste))
### 0.1.1
- Hugely improved parameter parsing to support both types of quotes in the same curl command (#36)
- Added the `-CompressJSON` parameter which attempts to compress the JSON body.
- Added new curl parameters (#35):
- `-k` and `--insecure`
- `-s` and `--silent`
- Added support for grouped, single char parameters such as `-ksX` (#35)### 0.1.0
- Added -u Curl parameter (thank you [@mavaddat!](https://github.com/mavaddat))
- Included Javascript to scrape curl parameters from the manpage (thank you [@mavaddat!](https://github.com/mavaddat))
- Changed `ConvertTo-IRM`'s `-String` parameter to `-CommandAsString`.
- Added `[OutputType]` to all commands.
- Updated docs.### Other Credits
- Implemented classes and class based pester testing (thank you [@Stephanevg](https://github.com/Stephanevg))