lib/Example.ps1
Function Get-ZertoItem { [CmdletBinding()] param( [Parameter(Mandatory = $false, HelpMessage = 'Zerto Session Name')][String]$ZertoSession = "Default" ) ## Get Session Configuration $ZertoSessionConfig = $global:ZertoSessions[$ZertoSession] if (-not $ZertoSessionConfig) { Write-Host 'TMSession: [' -NoNewline Write-Host $ZertoSession -ForegroundColor Cyan Write-Host '] was not Found. Please use the New-ZertoSession command.' Throw "Zerto Session Not Found. Use New-TMSession command before using features." } #Honor SSL Settings if ($ZertoSessionConfig.AllowInsecureSSL) { $ZertoCertSettings = @{SkipCertificateCheck = $true } } else { $ZertoCertSettings = @{SkipCertificateCheck = $false } } $baseURL = "https://" + $ZertoSessionConfig.ZertoServer + ":" + $ZertoSessionConfig.ZertoPort + "/v1/" $TypeJSON = "application/json" $FullURL = $baseURL + "localsite" Write-Verbose $FullURL try { $RestMethodSplat = @{ Uri = $FullURL TimeoutSec = 100 ContentType = $TypeJSON Method = 'GET' WebSession = $ZertoSessionConfig.ZertoWebSession } $Result = Invoke-RestMethod @RestMethodSplat @ZertoCertSettings } catch { throw $_.Exception.Message } return $Result } |