scripts/helpers.ps1

# HPE Nimble PowerShell Toolkit.
# File: helpers.ps1
# Description: This file contains common helper routines. These functions are called by generated SDK Cmdlet functions.
#
# © Copyright 2017 Hewlett Packard Enterprise Development LP.
function Connect-NSGroup {
<#
.SYNOPSIS
    Connects to a Nimble Storage group.
.DESCRIPTION
    Connect-NSGroup is an advanced function that provides the initial connection to a Nimble Storage
    array so that other subsequent commands can be run without having to authenticate individually.
    It is recommended to ignore the server certificate validation (-IgnoreServerCertificate param)
    since Nimble uses an untrusted SSL certificate.
.PARAMETER Group
    The DNS name or IP address of the Nimble group.
.PARAMETER Credential
    Specifies a user account that has permission to perform this action. Type a user name, such as User01
    or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a
    user name, this function prompts you for a password.
.PARAMETER IgnoreServerCertificate
    Ignore the server SSL certificate.
.EXAMPLE
     Connect-NSGroup -Group nimblegroup.yourdns.local -Credential admin -IgnoreServerCertificate
 
     *Note: IgnoreServerCertificate parameter is not available with PowerShell Core
.EXAMPLE
     Connect-NSGroup -Group 192.168.1.50 -Credential admin -IgnoreServerCertificate
 
     *Note: IgnoreServerCertificate parameter is not available with PowerShell Core
.EXAMPLE
     Connect-NSGroup -Group nimblegroup.yourdns.local -Credential admin -ImportServerCertificate
.EXAMPLE
     Connect-NSGroup -Group 192.168.1.50 -Credential admin -ImportServerCertificate
.INPUTS
    None
.OUTPUTS
    None
.NOTES
 
#>

    [cmdletbinding(DefaultParameterSetName='IgnoreServerCertificate')]
    param   (
        [Parameter(Mandatory,position=0)]
        [string]$Group,

        [Parameter(Mandatory,position=1)]
        $Credential=$null,
        

        [Parameter(ParameterSetName='ImportServerCertificate')]
        [switch]$ImportServerCertificate
    
    )

    DynamicParam {

            if ($PSEdition -ne 'Core'){ 

                 $IgnoreServerCertificateAttribute = New-Object System.Management.Automation.ParameterAttribute
                 $IgnoreServerCertificateAttribute.Mandatory = $false
                 #$IgnoreServerCertificateAttribute.Position = 3
                 $IgnoreServerCertificateAttribute.ParameterSetName = 'IgnoreServerCertificate'
                 $attributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
                 $attributeCollection.Add($IgnoreServerCertificateAttribute)  
                 $IgnoreServerCertificateParam = New-Object System.Management.Automation.RuntimeDefinedParameter('IgnoreServerCertificate', [Switch],$attributeCollection)
                 $paramDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
                 $paramDictionary.Add('IgnoreServerCertificate', $IgnoreServerCertificateParam)
                 return $paramDictionary
                 }
            }

    Process{

        if ($Credential -is [String]) {
            $Credential = Get-Credential $Credential
         }
         $global:Group=$Group
        if ($PSBoundParameters.IgnoreServerCertificate) { $Global:NimbleStorageIgnoreServerCertificate = $true; IgnoreServerCertificate}

        else 
            {
                 $Global:NimbleStorageIgnoreServerCertificate = $false
                 $Global:GlobalImportServerCertificate = $ImportServerCertificate
                 ValidateServerCertificate $group
            }

        Import-LocalizedData -BaseDirectory (Split-Path $PSScriptRoot -parent) -FileName "HPENimblePowerShellToolkit.psd1" -BindingVariable "ModuleData"
        $PSTKVersion = $ModuleData.moduleversion
        $Global:NimbleAppName = "HPENimblePowerShellToolkitV" + $PSTKVersion
        $Global:NimbleStoragePort = 5392
        $Global:BaseUri = "https://$($global:Group):$($NimbleStoragePort)"
        try{
            $Global:NimbleStorageTokenData = Invoke-RestMethod -Uri "$BaseUri/v1/tokens" -Method Post -Body ((@{data = @{username = $Credential.UserName;password = $Credential.GetNetworkCredential().password;app_name = $NimbleAppName}}) | ConvertTo-Json)
            Write-Host "Successfully connected to array $group `n`n"
        }
        catch{
            Write-error "Failed to connect with array $group `n`n $_.Exception.Message" -ErrorAction Stop
        }
        $Global:RestVersion = (Invoke-RestMethod -Uri "$BaseUri/versions").data.name
        $Global:NimbleStorageSession_token = $NimbleStorageTokenData.data.session_token
        $Global:NimbleStorageArray = $group
        $Global:NimbleStorageCommonPSParams=@('Debug','Verbose','ErrorAction','ErrorVariable','InformationAction','InformationVariable','OutBuffer','OutVariable','PipelineVariable','Verbose','WarningAction','WarningVariable','WhatIf','Confim','ItemType')
    }
}

function Disconnect-NSGroup {
<#
.SYNOPSIS
    Disconnects from a Nimble SAN.
.DESCRIPTION
    Disconnect-NSGroup is an advanced function that disconnects the established connection with Nimble Storage
    array.
.EXAMPLE
    Disconnect-NSGroup
.INPUTS
    None
.OUTPUTS
    None
.NOTES
 
#>

    [CmdletBinding()]
    param ( )
    if (Get-Variable NimbleStorageTokenData -Scope Global -ErrorAction SilentlyContinue)
    {
        Remove-NSToken -id $NimbleStorageTokenData.data.id
        remove-Variable -Scope "Global" NimbleStoragePort
        Remove-Variable -Scope "Global" BaseUri
        Remove-Variable -Scope "Global" NimbleStorageTokenData
        Remove-Variable -Scope "Global" RestVersion
        Remove-Variable -Scope "Global" NimbleStorageSession_token
        Remove-Variable -Scope "Global" NimbleStorageArray
        Remove-Variable -Scope "Global" NimbleStorageCommonPSParams
    }
}

function IgnoreServerCertificate {

    [CmdletBinding()]
    param()
    <#
  [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
  [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
 
  add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
 
    public class IDontCarePolicy : ICertificatePolicy {
      public IDontCarePolicy() {}
      public bool CheckValidationResult(
        ServicePoint sPoint, X509Certificate cert,
        WebRequest wRequest, int certProb) {
        return true;
      }
    }
"@
 
  [System.Net.ServicePointManager]::CertificatePolicy = new-object IDontCarePolicy
    write-verbose 'Server certificate ignored'
    #>

     if (-not ([System.Management.Automation.PSTypeName]'CustomCertificateValidationCallback').Type)
    {

      add-type @"
      using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
 
    public static class CustomCertificateValidationCallback {
        public static void Install()
        {
            ServicePointManager.ServerCertificateValidationCallback += CustomCertificateValidationCallback.CheckValidationResult;
        }
 
 
        public static bool CheckValidationResult(
            object sender,
            X509Certificate certificate,
            X509Chain chain,
            SslPolicyErrors sslPolicyErrors)
        {
            // please don't do this. do some real validation with explicit exceptions.
            return true;
        }
    }
"@

    }

    [CustomCertificateValidationCallback]::Install()
}

function Invoke-NimbleStorageRestAPI ()
{
    param(
        [Parameter(Mandatory=$true)][string] $ResourcePath,
        [string] $APIVersion = 'v1',
        [string] $Method = 'GET',
        [hashtable] $RequestParams = @{}
    )

    if (!(Get-Variable NimbleStorageTokenData -Scope Global -ErrorAction SilentlyContinue)) {
       Write-Error -Message "Authentication Info missing. Please use Connect-NSGroup to login." -ErrorAction Stop
    }

    if ( $NimbleStorageIgnoreServerCertificate ) { IgnoreServerCertificate }

    # Form the parameters to Invoke-RestMethod call.
    $WebRequestParams = @{
        Uri = "$BaseUri/$APIVersion/$ResourcePath"
        Header = @{'X-Auth-Token' = $NimbleStorageSession_token}
        Method = $Method
    }

    # Copy request params to different variable. We may need to specifically process few of them.
    $RequestData = @{}
    foreach ($key in $RequestParams.keys)
    {
        # PowerShell serializes Booleans in JSON as True/False. We need all lowercase for Nimble Array's REST Server.
        if ($RequestParams.$key.getType() -eq [bool])
        {
            $RequestData.Add($key, $RequestParams.$key.ToString().ToLower())
        }
        elseif ($key -eq 'fields' -and $Method -eq 'GET')
        {
            # Array of fields. Convert to comma separated list.
            $RequestData.Add('fields', ($RequestParams['fields'] | Select-Object -unique) -join ',')
        }
        else
        {
            $RequestData.Add($key, $RequestParams.$key);
        }
    }

    switch($Method) {
        'GET' {
            # Hashmap supplied in Body for GET request gets converted to query params automatically.
            $WebRequestParams.Add('Body',$RequestData)
        }

        'POST' {
            # Encapsulate request payload in 'data'..
            $RequestDataForNimbleAPI = @{
                data = $RequestData
            }

            $WebRequestParams.Add('Body',($RequestDataForNimbleAPI | ConvertTo-Json -Depth 10))
        }

        'PUT'{
            $RequestDataForNimbleAPI = @{
                data = $RequestData
            }

            $WebRequestParams.Add('Body',($RequestDataForNimbleAPI | ConvertTo-Json -Depth 10))
        }

        'DELETE' {
            # Do nothing. No Body expected/required for delete request.
        }
    }

    Write-Verbose ($WebRequestParams | ConvertTo-Json -Depth 50)
    $max_retry_count = 5
    $retry_count = 0

    do {
        try
            {
          
              if ($retry_count -ne 0)
              {
                Start-Sleep -Milliseconds 30
              }
              $JsonResponse = (Invoke-RestMethod @WebRequestParams  | ConvertTo-Json -Depth 50)
              Write-Verbose "Server Response: $JsonResponse"

              #
              # The Invoke-Restmethod was successful we should exit the retry loop.
              # To do that we will force the retry count max surpass the max.
              #
              $retry_count  = $max_retry_count  + 1
            }
        catch
        {
            if ($_.Exception.Response -ne $null) 
            {
               APIExceptionHandler
            }
            else
            {     
                # if the Error response buffer is null then we will go for retries.
                # if we exhaust the retries we will thrown and error.
                $retry_count = $retry_count + 1
                
                if ($retry_count -gt $max_retry_count)
                {
                    Write-Verbose $_.exception
                    Write-Error "Error occoured while invoking restapi method, Please retry" -ErrorAction Stop 
                }

            }
        }
      
   }until ($retry_count -gt $max_retry_count) 
   
    return ($JsonResponse | ConvertFrom-Json)
}

function Get-NimbleStorageAPIObject()
{
    param(
        [Parameter(Mandatory=$true)][string] $ObjectName,
        [Parameter(Mandatory=$true)][string] $APIPath,
        [Parameter(Mandatory=$true)][string] $Id,
        [System.Collections.ArrayList] $Fields
    )

    $Params = @{
        ResourcePath = $APIPath + "/$Id"
        Method = 'GET'
    }

    if ($Fields)
    {
        $Params.Add('RequestParams', @{ fields = ($Fields | Select-Object) -join ','})
    }

    $APIObject = (Invoke-NimbleStorageRestAPI @Params).data
    $DataSetType = "NimbleStorage.$ObjectName"
    $APIObject.PSTypeNames.Insert(0,$DataSetType)
    $DataSetType = $DataSetType + ".TypeName"
    $APIObject.PSObject.TypeNames.Insert(0,$DataSetType)

    return $APIObject
}

function Get-NimbleStorageAPIObjectList()
{
    param(
        [Parameter(Mandatory=$true)][string] $ObjectName,
        [Parameter(Mandatory=$true)][string] $APIPath,
        [hashtable] $Filters,
        [System.Collections.ArrayList] $Fields
    )

    # First fetch all the objects (only id and name) matching the given filter.
    # Then for each of the objects, retrieve either all the details or given fields.
    $Params = @{
        ResourcePath = $APIPath
        Method = 'GET'
        RequestParams = $Filters
    }

    # Get the list of objects matching given criteria
    $JSONResponseObject = (Invoke-NimbleStorageRestAPI @Params)
    [System.Collections.ArrayList] $APIObjects = $JSONResponseObject.data

    # We are expecting a list. If total items/objects on the array for this query are more than 1024,
    # array will send back only first 1024 objects along with total count of objects in 'totalRows'.
    if ($JSONResponseObject.endRow -and $JSONResponseObject.totalRows -and ($JSONResponseObject.endRow -lt $JSONResponseObject.totalRows))
    {
        # There are more objects. Keep getting those until we reach the end.
        while ($JSONResponseObject.endRow -lt $JSONResponseObject.totalRows)
        {
            $Params.RequestParams.startRow = $JSONResponseObject.endRow
            $JSONResponseObject = Invoke-NimbleStorageRestAPI @Params
            $APIObjects.AddRange($JSONResponseObject.data) | out-null
        }
    }

    [System.Collections.ArrayList] $APIObjectsDetailed = @()

    # Fetch needed detailes of all the objects.
    foreach ($APIObject in $APIObjects)
    {
        $Params = @{
            ObjectName = $ObjectName
            APIPath = $APIPath
            Id = $APIObject.id
        }
        if ($Fields)
        {
            $Params.Add('Fields', $Fields)
        }

        $APIObject = (Get-NimbleStorageAPIObject @Params)
        $DataSetType = "NimbleStorage.$ObjectName"
        $APIObject.PSTypeNames.Insert(0,$DataSetType)
        $DataSetType = $DataSetType + ".TypeName"
        $APIObject.PSObject.TypeNames.Insert(0,$DataSetType)
        $APIObjectsDetailed.Add($APIObject) | out-null
    }
    Write-Verbose ("Found " + $APIObjectsDetailed.Count + " objects.")
    return ,$APIObjectsDetailed
}

function New-NimbleStorageAPIObject()
{
    param(
        [Parameter(Mandatory=$true)][string] $ObjectName,
        [Parameter(Mandatory=$true)][string] $APIPath,
        [Parameter(Mandatory=$true)][hashtable] $Properties
    )

    $Params = @{
        ResourcePath = $APIPath
        Method = 'POST'
        RequestParams = $Properties
    }

    $ResponseObject = (Invoke-NimbleStorageRestAPI @Params)
    $APIObject = $ResponseObject.data
    if ($APIObject)
    {$DataSetType = "NimbleStorage.$ObjectName"
        $APIObject.PSTypeNames.Insert(0,$DataSetType)
        $DataSetType = $DataSetType + ".TypeName"
        $APIObject.PSObject.TypeNames.Insert(0,$DataSetType)
    }
    else
    {
        $APIObject = $ResponseObject
        $DataSetType = "NimbleStorage.Messages"
        $APIObject.PSTypeNames.Insert(0,$DataSetType)
        $DataSetType = $DataSetType + ".TypeName"
        $APIObject.PSObject.TypeNames.Insert(0,$DataSetType)
    }

    return $APIObject
}

function Set-NimbleStorageAPIObject()
{
    param(
        [Parameter(Mandatory=$true)][string] $ObjectName,
        [Parameter(Mandatory=$true)][string] $APIPath,
        [Parameter(Mandatory=$true)][string] $Id,
        [Parameter(Mandatory=$true)][hashtable] $Properties
    )

    $Params = @{
        ResourcePath = $APIPath + "/$Id"
        Method = 'PUT'
        RequestParams = $Properties
    }

    $ResponseObject = (Invoke-NimbleStorageRestAPI @Params)
    $APIObject = $ResponseObject.data
    if ($APIObject)
    {$DataSetType = "NimbleStorage.$ObjectName"
        $APIObject.PSTypeNames.Insert(0,$DataSetType)
        $DataSetType = $DataSetType + ".TypeName"
        $APIObject.PSObject.TypeNames.Insert(0,$DataSetType)
    }
    else
    {
        $APIObject = $ResponseObject
        $DataSetType = "NimbleStorage.Messages"
        $APIObject.PSTypeNames.Insert(0,$DataSetType)
        $DataSetType = $DataSetType + ".TypeName"
        $APIObject.PSObject.TypeNames.Insert(0,$DataSetType)
    }

    return $APIObject
}

function Remove-NimbleStorageAPIObject()
{
    param(
        [Parameter(Mandatory=$true)][string] $ObjectName,
        [Parameter(Mandatory=$true)][string] $APIPath,
        [Parameter(Mandatory=$true)][string] $Id
    )

    $Params = @{
        ResourcePath = $APIPath + "/$Id"
        Method = 'DELETE'
    }

    $APIObject = (Invoke-NimbleStorageRestAPI @Params).data
}

function Invoke-NimbleStorageAPIAction()
{
    param(
        [Parameter(Mandatory=$true)][string] $APIPath,
        [Parameter(Mandatory=$true)][string] $Action,
        [Parameter(Mandatory=$true)][hashtable] $Arguments,
        [Parameter(Mandatory=$true)][string] $ReturnType
    )

    $Params = @{
        ResourcePath = $APIPath + "/actions/$Action"
        Method = 'POST'
        RequestParams = $Arguments
    }

    if ($Arguments.id)
    {
        $id = $($Arguments.id)
        $Params.ResourcePath = $APIPath + "/$id/actions/$Action"
        $Arguments.Remove('id')
    }

    $ResponseObject = (Invoke-NimbleStorageRestAPI @Params)
    if ($ReturnType -eq "void")
    {
        # Return empty object
        return $ResponseObject
    }
    $APIObject = $ResponseObject.data
    $DataSetType = "NimbleStorage.$ReturnType"
    $APIObject.PSTypeNames.Insert(0,$DataSetType)
    $DataSetType = $DataSetType + ".TypeName"
    $APIObject.PSObject.TypeNames.Insert(0,$DataSetType)

    return $APIObject
}


function ValidateServerCertificate() 
{

    param(
    [Parameter(Mandatory,Position=0)]
        [string]$Group )


    $Code = @'
        using System;
        using System.Collections.Generic;
        using System.Net.Http;
        using System.Net.Security;
        using System.Security.Cryptography.X509Certificates;
 
        namespace CertificateCapture
        {
            public class Utility
            {
                 public static Func<HttpRequestMessage,X509Certificate2,X509Chain,SslPolicyErrors,Boolean> ValidationCallback =
                    (message, cert, chain, errors) => {
                        var newCert = new X509Certificate2(cert);
                        var newChain = new X509Chain();
                        newChain.Build(newCert);
                        CapturedCertificates.Add(new CapturedCertificate(){
                            Certificate = newCert,
                            CertificateChain = newChain,
                            PolicyErrors = errors,
                            URI = message.RequestUri
                        });
                        return true;
                    };
                public static List<CapturedCertificate> CapturedCertificates = new List<CapturedCertificate>();
            }
 
            public class CapturedCertificate
            {
                public X509Certificate2 Certificate { get; set; }
                public X509Chain CertificateChain { get; set; }
                public SslPolicyErrors PolicyErrors { get; set; }
                public Uri URI { get; set; }
            }
        }
'@


if ($PSEdition -ne 'Core'){
    $webrequest=[net.webrequest]::Create("https://$Group")
    try { $response=$webrequest.getresponse() } catch {}
    $cert=$webrequest.servicepoint.certificate
    if($cert -ne $null){
            $Thumbprint = $webrequest.ServicePoint.Certificate.GetCertHashString()
            $bytes=$cert.export([security.cryptography.x509certificates.x509contenttype]::cert)
            $tfile=[system.io.path]::getTempFileName()
            set-content -value $bytes -encoding byte -path $tfile
            $certdetails = $cert | select * | ft -AutoSize | Out-String
            if ($($GlobalImportServerCertificate))  
            {   
                try{
                    $output =import-certificate -filepath $tfile -certStoreLocation 'Cert:\localmachine\Root'
                    $certdetails = $output | select -Property Thumbprint,subject | ft -AutoSize | Out-String
                    }
                catch{
                    Write-Error "Failed to import the server certificate `n`n $_.Exception.Message"  -ErrorAction Stop
                }
                Write-Host "Successfully imported the server certificate `n $certdetails"
            }
            else{
                 if((Get-ChildItem -Path Cert:\LocalMachine\root | Where-Object {$_.Thumbprint -eq $Thumbprint})){ }                
                 else{
                        write-Error "The security certificate presented by host $Group was not issued by a trusted certificate authority. Please verify the certificate details shown below and use ImportServerCertificate command line parameter to proceed. `n $certdetails `n`n" -ErrorAction Stop 
                     }
            }

             ResolveIPtoHost $cert.subject $Group


        }
    else{
            Write-Error "Failed to import the server certificate `n`n"  -ErrorAction Stop

        }  
}else { 
        Add-Type $Code
        $Certs = [CertificateCapture.Utility]::CapturedCertificates
        $Handler = [System.Net.Http.HttpClientHandler]::new()
        $Handler.ServerCertificateCustomValidationCallback = [CertificateCapture.Utility]::ValidationCallback
        $Client = [System.Net.Http.HttpClient]::new($Handler)
        $Url = "https://$Group"
        $Result = $Client.GetAsync($Url).Result
        $cert= $Certs[-1].Certificate
        if($certs -ne $null){
            $certdetails = $cert | select -Property Thumbprint,subject | ft -AutoSize | Out-String
            if ($($GlobalImportServerCertificate))  
            {
                $bytes=$cert.export([security.cryptography.x509certificates.x509contenttype]::cert)
                $OpenFlags = [System.Security.Cryptography.X509Certificates.OpenFlags]
                $store = new-object system.security.cryptography.X509Certificates.X509Store -argumentlist "Root","LocalMachine"
                try{
                        $Store.Open($OpenFlags::ReadWrite)
                        $Store.Add($Cert)
                        $Store.Close()
                        Write-Host "Successfully imported the server certificate `n $certdetails" 
                    }
                catch{
                        Write-Error "Failed to import the server certificate `n`n $_.Exception.Message"  -ErrorAction Stop
                }
            }
            else
            {
               if((Get-ChildItem -Path Cert:\LocalMachine\root | Where-Object {$_.Thumbprint -eq $cert.Thumbprint})){ }                
                 else{
                        write-Error "The security certificate presented by host $Group was not issued by a trusted certificate authority. Please verify the certificate details shown below and use ImportServerCertificate command line parameter to proceed. `n $certdetails `n`n" -ErrorAction Stop 
                     }
            }
             ResolveIPtoHost $cert.subject $Group
        }
        else{
            Write-Error "Failed to import the server certificate `n`n"  -ErrorAction Stop
        }


}
}
function ResolveIPtoHost{

 param(
    [Parameter(Mandatory)]
        [string]$CertSubject, 
        
    [Parameter(Mandatory)]
        [string]$Group
        )

            # we will check if the host name given as input matches the host name in the certificate.
            # if IP is given as input and the certificate has hostname (FQDN) then we will use the hostname name but
            # before that we will ensurelookup from hostname to IP works.
            
            $cert_hostname = ($CertSubject.Substring(($CertSubject.IndexOf("=")+1),($CertSubject.IndexOf(",")-3))).trim()
            
            # check if the input and cert hostname matches, if yes we are good to go
            # Else the input must have ben the IP address, we will if cert hostname can be resolved to match the input hostname (IP).
            if ($Group -ne $cert_hostname)
            {
                # we will look up the DNS to resolve the cert_hostname.
                # we could do this with either cert hostname or ibput hostname(IP), but cert hostname has better chance of getting resolved.
                
                try
                {
                    $resolved_name = [System.Net.DNS]::GetHostEntry($cert_hostname).AddressList 
                    $resolved_name = $resolved_name | select -ExpandProperty IPAddressToString
                   # $Group = $resolved_name
                    # will come here if the host got resolved.
                    
                     Write-Verbose " $cert_hostname is host-name for provided input $Group IP address"
                    
                    if ($resolved_name -ne $Group)             
                    {
                        # most probably this will not happen, just to be defensive adding this code.
                        # this is the same host as the certificate hostname got resolved to the input hostname(IP)
                        # we will start using the cert hostname for all the calls from this point in this session.
                        
                        Write-Error "Unable to resolve the certificate hostname to match the provided input hostname/IP. `n`n $_.Exception.Message"  -ErrorAction Stop
                    }
                    else
                    {
                        # we are good to go.
                        Write-Verbose " Resolved name and input name matches: $Group IP address"
                        $global:Group = $cert_hostname
                    }

                }
                catch 
                {
                    # unable to resolve the cert hostname. Host not reachable. Error out!.
                    Write-Error "Unable to resolve the certificate hostname. Host not reachable. `n`n $_.Exception.Message"  -ErrorAction Stop
                }

            }
            else
            {
                # we are good to go.
                
                Write-Verbose "Host-name given as input matches with certificate name"
            }
             


}

Function APIExceptionHandler
{
   #Exception message handle differently for core and non core environment
   #GetResponseStream method does not work in core environment

   if(Get-Member -inputobject $_.Exception.Response -name "GetResponseStream" -Membertype Method)
   {
       $JsonResponse = $_.Exception.Response.GetResponseStream()
       $reader = New-Object System.IO.StreamReader($JsonResponse)
       $reader.BaseStream.Position = 0
       $reader.DiscardBufferedData()
       $responseBody = $reader.ReadToEnd();
       if (($responseBody | ConvertFrom-Json).messages -ne $null)
       {
           foreach( $errorMsg in ($responseBody | ConvertFrom-Json).messages) {
           if($errorMsg.text -ne $null) {$exceptionString += $errorMsg.text + " "}
       }
       throw [System.Exception] $exceptionString
       }
       else
       {
           throw $_.Exception
       }
   }
   else
   {
        
        $responseBody = $_.ErrorDetails
       if (($responseBody | ConvertFrom-Json).messages -ne $null)
       {
           foreach( $errorMsg in ($responseBody | ConvertFrom-Json).messages) {
           if($errorMsg.text -ne $null) {$exceptionString += $errorMsg.text + " "}
       }
       throw [System.Exception] $exceptionString
       }
       else
       {
           throw $_.Exception
       }
   }       
}
# SIG # Begin signature block
# MIIiUgYJKoZIhvcNAQcCoIIiQzCCIj8CAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCDidTDS8U60Ltza
# 425ucKonwVu33bD4r6ZjtGmnBlXjaqCCEIwwggVRMIIEOaADAgECAhAqlTIY4QtL
# e2/RSyqeww0mMA0GCSqGSIb3DQEBCwUAMIG9MQswCQYDVQQGEwJVUzEXMBUGA1UE
# ChMOVmVyaVNpZ24sIEluYy4x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