TomTom30
TomTom30

Reputation: 35

Use this curl command with Invoke-webrequest?

I have this curl command:

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

How to convert this curl command to a powershell command?

Upvotes: 0

Views: 2063

Answers (2)

FoxDeploy
FoxDeploy

Reputation: 13537

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.

Upvotes: 2

Avshalom
Avshalom

Reputation: 8889

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

Upvotes: 1

Related Questions