Update Invoke-ZertoRestRequest.ps1
This commit is contained in:
@@ -63,6 +63,7 @@ function Invoke-ZertoRestRequest {
|
|||||||
Headers = $headers
|
Headers = $headers
|
||||||
Body = $body
|
Body = $body
|
||||||
TimeoutSec = 100
|
TimeoutSec = 100
|
||||||
|
ContentType = "application/json"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Handle authentication requests
|
# Handle authentication requests
|
||||||
@@ -77,19 +78,19 @@ function Invoke-ZertoRestRequest {
|
|||||||
$params.Uri = "https://{0}:{1}/auth/realms/zerto/protocol/openid-connect/token" -f $script:zvmServer, $script:zvmPort
|
$params.Uri = "https://{0}:{1}/auth/realms/zerto/protocol/openid-connect/token" -f $script:zvmServer, $script:zvmPort
|
||||||
$params.Body = $data
|
$params.Body = $data
|
||||||
$params.ContentType = "application/x-www-form-urlencoded"
|
$params.ContentType = "application/x-www-form-urlencoded"
|
||||||
} else {
|
|
||||||
$params.ContentType = "application/json"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Handle certificate validation for PowerShell 5.1
|
# Handle certificate validation for PowerShell 5.1
|
||||||
if ($PSVersionTable.PSVersion.Major -ge 6) {
|
if ($PSVersionTable.PSVersion.Major -ge 6) {
|
||||||
$params["SkipCertificateCheck"] = $true
|
$params["SkipCertificateCheck"] = $true
|
||||||
} elseif ([System.Net.ServicePointManager]::CertificatePolicy.GetType().Name -ne "TrustAllCertsPolicy") {
|
$apiRequestResults = Invoke-RestMethod @params -ResponseHeadersVariable responseHeaders
|
||||||
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
|
} else {
|
||||||
|
# PowerShell 5.1 workaround since `-ResponseHeadersVariable` is not available
|
||||||
|
$webResponse = Invoke-WebRequest @params
|
||||||
|
$apiRequestResults = $webResponse.Content | ConvertFrom-Json -ErrorAction SilentlyContinue
|
||||||
|
$responseHeaders = $webResponse.Headers
|
||||||
}
|
}
|
||||||
|
|
||||||
$apiRequestResults = Invoke-RestMethod @params -ResponseHeadersVariable responseHeaders
|
|
||||||
|
|
||||||
# Debugging - Inspect Response Type
|
# Debugging - Inspect Response Type
|
||||||
Write-Verbose "Response Type: $($apiRequestResults.GetType().FullName)"
|
Write-Verbose "Response Type: $($apiRequestResults.GetType().FullName)"
|
||||||
Write-Verbose "Response Content: $($apiRequestResults | ConvertTo-Json -Depth 10)"
|
Write-Verbose "Response Content: $($apiRequestResults | ConvertTo-Json -Depth 10)"
|
||||||
|
|||||||
Reference in New Issue
Block a user