1

Can anyone give me a hint, how to convert following curl command to PS Invoke-Webrequest ?

curl -d {\"password\":\"$password\"\} $vault/v1/auth/userpass/login/${login,,}

I have some thoughts on this, but cannot figure out, how to finish this:

$vault="3.3.3.3:8500"
$pair = (Get-Credential)
$params = ????
$login = $pair.getNetworkCredential().username
$pass = $pair.getNetworkCredential().password

Invoke-WebRequest $url -Method Post -Credential $pair -Body $params -UseBasicParsing

How to correctly pass $params like in curl request?

1 Answer 1

3

the Params should be a hashtable @{}.

$Params = @{
    Username="TestName";
    Password="TestPassword";
    Places = @("Here","There");
}

Here is a example using a test API called jsonplaceholder

$url = 'https://jsonplaceholder.typicode.com/posts'

$params = @{
    title: 'foo'
    body: 'bar'
    userId:1
}

(Invoke-WebRequest $url -Method Post -Body $params -UseBasicParsing).content | ConvertFrom-JSON

Response

                                                     id
title: 'foo'                                       
body: 'bar'                                        
userId:1                                           

---------------------------------------------------  --
                                                    101

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.