Home > Back-end >  Use this curl command with Invoke-webrequest?
Use this curl command with Invoke-webrequest?

Time:10-06

I guys,

I have this curl command :

curl -s -k -X POST https://xxxx/rest/com/vmware/cis/session -u 'xxx':'xxx'

There is someone to show me how to convert this curl command in powershell command ?

CodePudding user response:

As it seems, you are trying to connect vCenter server rest api, here's how:

$Credential = Get-Credential
$vCenterServer = 'vcenter-server'
$auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Credential.UserName ':' $Credential.GetNetworkCredential().Password))
$AuthHeader = @{
  'Authorization' = "Basic $auth"
}

$conn = Invoke-WebRequest -Uri https://$vCenterServer/rest/com/vmware/cis/session -Method Post -Headers $AuthHeader

CodePudding user response:

Curl.exe ships with Windows as of Windows 10 1803, so every server or Windows client since about March of 2018.

You can use it natively from PowerShell, but only when you specify the full executable name.

In other words

curl someurl.com      //uses the curl alias, which actually calls Invoke-WebRequest

curl.exe someurl.com //actually uses the real curl.exe binary.
  • Related