[Powershell] Invoke-RestMethod call REST Api

cls

$authInfo = @{
username = “username"
password = “password"
}

$base64AuthInfo = [Convert]::ToBase64String(
[Text.Encoding]::ASCII.GetBytes(
(“{0}:{1}" -f $authInfo.username, $authInfo.password)))

$basePath = “http://path/to/baseUrl"

$uri = $basePath + “{0}" -f “/api/softwareInfo/version"

$resMsg = Invoke-RestMethod -Uri $uri -Headers @{Authorization=(“Basic {0}" -f $base64AuthInfo)} -Method Get

if($resMsg.version -ne $null)
{
echo $resMsg.version
return @{
username = $authInfo.username
password = $authInfo.password
uri = $basePath
}
}

廣告