public/Set-CTRecordingGeneral.ps1

Function Set-CTRecordingGeneral {
    [cmdletBinding(
        DefaultParameterSetName='Hanwha',
        #SupportsShouldProcess = $true,
        ConfirmImpact='high'
        )]
    Param(
        [Parameter(
            Mandatory=$true,
            ParameterSetName='Hanwha'
        )]
        [String]$IP,

        [Parameter(
            Mandatory=$true,
            ParameterSetName='Hanwha'
        )]
        [pscredential]$Credential,

        [Parameter(
            Mandatory=$false,
            ParameterSetName='Hanwha'
        )]
        [String]$Channel=0,

        [Parameter(
            Mandatory=$false,
            ParameterSetName='Hanwha'
        )]
        [String]$PreEventDuration,

        [Parameter(
            Mandatory=$false,
            ParameterSetName='Hanwha'
        )]
        [String]$PostEventDuration

    )
    DynamicParam {
        $DynamicParameters = @{
            CameraType = @{
                Mandatory = $true
                #Position = 1
                ParameterSetName = "Hanwha"
                Enum = $Script:SupportedCameraModels
            }
            Continuous = @{
                Mandatory = $true
                #Position = 2
                ParameterSetName = "Hanwha"
                Enum = @(
                    'I-Frame'
                    'Full'
                    'Off'
                )
                DefaultValue = 'Full'
            }
            Event = @{
                Mandatory = $false
                #Position = 3
                ParameterSetName = "Hanwha"
                Enum = @(
                    'I-Frame'
                    'Full'
                    'Off'
                )
                DefaultValue = 'Full'
            }
            FileType = @{
                Mandatory = $false
                #Position = 3
                ParameterSetName = "Hanwha"
                Enum = @(
                    'STW'
                    'AVI'
                )
                DefaultValue = 'AVI'
            }
        }
        
        return New-DynamicParameterSet -ParameterTable $DynamicParameters
    }
    Begin {
        Write-Debug "[Set-CTRecordingGeneral] Started"
        $CameraType = $PSBoundParameters.CameraType
        $Continuous = $PSBoundParameters.Continuous
        $CamEvent = $PSBoundParameters.Event
        $FileType = $PSBoundParameters.FileType

        if($CameraType -eq 'Hanwha') {
            #Set basic Paramters for Invoke-HanwhaCommand
            $CamCmd = @{
                Arguments = @{
                    IP = $IP
                    Menu = 'recording'
                    SubMenu = 'general'
                    Action = 'set'
                    Parameters = @()
                }
                Credential = $Credential
            }

            #Add Action Parameters
            $CamCmd.Arguments.Parameters += "Channel=$Channel"
            if($Continuous) {
                $CamCmd.Arguments.Parameters += "NormalMode=$Continuous"
            }
            if($PreEventDuration) {
                if($PreEventDuration -match '[A-Za-z]') {
                    $CamCmd.Arguments.Parameters += "PreEventDuration=$PreEventDuration"
                }
                else {
                    $CamCmd.Arguments.Parameters += "PreEventDuration=$($PreEventDuration)s"
                }
            }
            if($PostEventDuration) {
                if($PostEventDuration -match '[A-Za-z]') {
                    $CamCmd.Arguments.Parameters += "PostEventDuration=$PostEventDuration"
                }
                else {
                    $CamCmd.Arguments.Parameters += "PostEventDuration=$($PostEventDuration)s"
                }
            }
            if($FileType) {
                $CamCmd.Arguments.Parameters += "RecordedVideoFileType=$FileType"
            }

            #If event isn't set, use the value from Continuous
            if($CamEvent) {
                $CamCmd.Arguments.Parameters += "EventMode=$CamEvent"
            }
            elseif ($Continuous) {
                $CamCmd.Arguments.Parameters += "EventMode=$Continuous"
            }

            Invoke-HanwhaCommand @CamCmd
        }
    }
}