Update Invoke-ZertoRestRequest.ps1
This commit is contained in:
@@ -1,26 +1,29 @@
|
||||
function Invoke-ZertoRestRequest {
|
||||
[cmdletbinding()]
|
||||
param(
|
||||
[ValidateSet("GET", "PUT", "POST", "DELETE")]
|
||||
[string]$method = "GET",
|
||||
[Parameter(Mandatory)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$uri,
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$apiVersion = "v1",
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$body,
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$contentType = "application/json",
|
||||
[System.Management.Automation.PSCredential]
|
||||
$credential,
|
||||
[PSCredential]$credential,
|
||||
[switch]$returnHeaders
|
||||
)
|
||||
$callerErrorActionPreference = $ErrorActionPreference
|
||||
# If the ZVM server and Port not defined, Stop Call
|
||||
if ( -not ((Test-Path variable:script:zvmServer) -and (Test-Path variable:script:zvmPort)) ) {
|
||||
Write-Error -Message "Zerto Connection does not Exist. Please run Connect-ZertoServer first to establish a connection"
|
||||
break
|
||||
ThrowError -ExceptionName "NoConnection" -ExceptionMessage "Zerto Connection does not Exist. Please run Connect-ZertoServer first to establish a connection" -errorId "Connection01" -errorCategory "Connection" -ErrorAction Stop
|
||||
}
|
||||
|
||||
# If the Headers exist and the Last action was more than 30 minutes ago, Session is Expired
|
||||
if ( (Test-Path variable:script:zvmHeaders) -and $([datetime]$script:zvmLastAction).addMinutes(30) -lt $(get-date) ) {
|
||||
Write-Error -Message "Authorization Token has Expired. Please re-authorize to the Zerto Virtual Manager"
|
||||
break
|
||||
ThrowError -ExceptionName "ExpiredToken" -ExceptionMessage "Authorization Token has Expired. Please re-authorize to the Zerto Virtual Manager" -errorId "ZVMAuth01" -errorCategory "Auth" -ErrorAction Stop
|
||||
} else {
|
||||
|
||||
# Build the URI to be submitted
|
||||
|
||||
Reference in New Issue
Block a user