According to the above, the following code should work. However, I get a HTTP/401.
$VROPS = 'https://vrops-server/suite-api/api'
$contentType = 'application/json'
$logonURL = $VROPS + '/auth/token/acquire'
$creds = Get-Credential -UserName $env:USERNAME -Message 'VROPS Creds'
$username = $creds.UserName
$plaintext = $creds.GetNetworkCredential().password
$jsonBody = @{username="$username";password="$plaintext";authSource="DOMAIN"} | ConvertTo-Json
$response = Invoke-WebRequest -Method 'POST' -Uri $logonURL -ContentType $contentType -Body $jsonBody
I have tried with and without authSource (that got me locked out, so definitely it's hitting the domain).
Also, I tried with "-Body $jsonBody.ToString()" just in case.
Thanks, here's the trick: USERNAME@AUTHSOURCE
USERNAME = username only, not username@domain.com
The AUTHSOURCE must be appended.
$VROPS = 'https://vrops_server/suite-api/api'
# Authentication Source Display Name
$AUTHSOURCE = 'AUTH_SOURCE_DISPLAY_NAME'
$contentType = 'application/json'
$logonURL = $VROPS + '/auth/token/acquire'
$creds = Get-Credential -UserName "$($env:USERNAME)" -Message 'VROPS Creds'
$username = $creds.UserName + "@$($AUTHSOURCE)"
$plaintext = $creds.GetNetworkCredential().password
$jsonBody = @{username="$username";password="$plaintext"} | ConvertTo-Json
$response = Invoke-WebRequest -Method 'POST' -Uri $logonURL -ContentType $contentType -Body $jsonBody
Could this be the issue described in KB2103084?
Did you try the same with something like PostMan?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, here's the trick: USERNAME@AUTHSOURCE
USERNAME = username only, not username@domain.com
The AUTHSOURCE must be appended.
$VROPS = 'https://vrops_server/suite-api/api'
# Authentication Source Display Name
$AUTHSOURCE = 'AUTH_SOURCE_DISPLAY_NAME'
$contentType = 'application/json'
$logonURL = $VROPS + '/auth/token/acquire'
$creds = Get-Credential -UserName "$($env:USERNAME)" -Message 'VROPS Creds'
$username = $creds.UserName + "@$($AUTHSOURCE)"
$plaintext = $creds.GetNetworkCredential().password
$jsonBody = @{username="$username";password="$plaintext"} | ConvertTo-Json
$response = Invoke-WebRequest -Method 'POST' -Uri $logonURL -ContentType $contentType -Body $jsonBody