private/Functions/Hanwha/Get-HanwhaSnapshot.ps1

Function Get-HanwhaSnapshot {
    [cmdletBinding()]
    Param(
        [Parameter()]
        [hashtable]$Object
    )
    
    <#
    Object Definition:
    @{
        IP = [String(Mandatory)]
        Credential = [PSCredential(Mandatory)]
        Channel = [int] as [String(Optional)]
        Path = [int] as [String(Mandatory)]
    }
    #>

    Write-Debug "[Get-HanwhaSnapshot] Started"
    $Channel = 0
    if($Object.ContainsKey('Channel') -and $Object.Channel) {
        $Channel = $Object.Channel
    }
    Write-Debug "Channel:$Channel"
    #Check for MJPEG Profile
    $obj = @{
        IP = $Object.IP
        Credential = $Object.Credential
        Channel = $Channel
        ProfileId = 3
    }
    $MediaProfile = Get-HanwhaMediaProfile $obj

    if($MediaProfile.EncodingType -ne 'MJPEG') {
        Write-Warning -Message "Adding MJPEG Support to Profile 3"

        $obj = @{
            IP = $Object.IP
            Credential = $Object.Credential
            ProfileID = 3
            NewName = "Snapshot"
            Channel = $Channel
            Encoding = 'MJPEG'
        }
        Update-HanwhaMediaProfile $obj
    }

    #Can't use Invoke-HanwhaCommand because we need Invoke-WebRequest
    $Param = @{
        Uri = "https://$($Object.IP)/stw-cgi/video.cgi?msubmenu=snapshot&action=view&Channel=$Channel&Profile=3"
        OutFile = $Object.OutFile
        Credential = $Object.Credential
    }

    if($PSVersionTable.PSVersion.Major -gt 5) {
        $Param.Add('SkipCertificateCheck',$true)
    }
    else {
        $Param.Add('UseBasicParsing',$true)
    }
    $NULL = Invoke-WebRequest @Param
}