private/Functions/Axis/Invoke-AxisCommand.ps1

Function Invoke-AxisCommand {
    [cmdletBinding(
        DefaultParameterSetName='Object',
        #SupportsShouldProcess = $true,
        ConfirmImpact='high'
        )]
    Param(
        [Parameter(
            Mandatory=$false,
            ParameterSetName='Object'
        )]
        [Hashtable]$Arguments,

        [Parameter(
            Mandatory=$false,
            ParameterSetName='URI'
        )]
        [String]$Uri,
        
        [Parameter(
            Mandatory=$true,
            ParameterSetName='Object'
        )]
        [Parameter(
            Mandatory=$true,
            ParameterSetName='URI'
        )]
        [pscredential]$Credential
    )

    <#
    Arguments = @{
        IP = $IP
        Menu = 'recording'
        SubMenu = 'general'
        Action = 'set'
        Parameters = @()
    }
    #>


    if(!$Uri) {
        #Validate Input Object
        if(
            !$Arguments.IP -or
            !$Arguments.Menu -or
            !$Arguments.SubMenu -or
            !$Arguments.Action
        ) {
            Throw "Cannot Invoke Command without IP, Menu, SubMenu, and Action"
        }

        if($Arguments.Action.toLower() -eq 'set' -and $Arguments.Parameters.length -lt 1) {
            Throw "Cannot Invoke Set commmand without Parameters"
        }

        #Build URI
        $Uri = "https://$($Arguments.IP)/stw-cgi/$($Arguments.Menu).cgi?msubmenu=$($Arguments.SubMenu)&action=$($Arguments.Action)"

        if($Arguments.Parameters.length -gt 0) {
            ForEach ($arg in $Arguments.Parameters) {
                $Uri += "&$($arg)"
            }
        }
    }

    $Param = @{
        Method = 'GET'
        Uri = $Uri
        Credential = $Credential
        #SkipCertificateCheck = $true
        Headers = @{
            Accept = 'application/json'
        }
    }

    if($PSVersionTable.PSVersion.Major -gt 5) {
        $Param.Add('SkipCertificateCheck',$true)
    }

    Write-Debug "URI: $Uri"
    $result = Invoke-RestMethod @Param

    #Handle Results
    $ResultProperties = @{}
    $result.psobject.Properties | ForEach-Object {
        $ResultProperties.Add($_.Name,$_.Value)
    }

    #Output of Successful View commands will not contain a 'Response'
    if(!$ResultProperties.ContainsKey('Response')) {
        return $result
    }

    if($ResultProperties['Response'] -ne 'Success') {
            $Param = @{
                ExceptionName = "System.Management.Automation.CmdletInvocationException"
                ExceptionMessage = $result.Error.Details
                ErrorId = $result.Error.Code 
                CallerPSCmdlet = $PSCmdlet
                ErrorCategory = 'DeviceError'
            }
            ThrowError @Param
    }

}