Функция запроса

function Get-Onvif {
    Param(
        [Parameter(Mandatory = $true)]
        $tdsIP,
        [Parameter(Mandatory = $false)]
        [string]$tdsPort = "8899",
        [Parameter(Mandatory = $true)]
        [string]$tdsBody
    )


    try {

        $endPoint = "http://" + $tdsIP + ":" + $tdsPort + "/onvif/device_service"
        #Write-Host ("Querying "+$endPoint)
        $wr = [System.Net.HttpWebRequest]::Create($endPoint)
        $wr.Method= 'POST'
        $wr.ContentType="application/xml"
        $Body = [byte[]][char[]]$tdsBody
        $wr.Timeout = 10000

        $Stream = $wr.GetRequestStream()

        $Stream.Write($Body, 0, $Body.Length)

        $Stream.Flush()
        $Stream.Close()

        $resp = $wr.GetResponse().GetResponseStream()
        $sr = New-Object System.IO.StreamReader($resp)
        $respTxt = $sr.ReadToEnd()

        [System.Xml.XmlDocument] $result = $respTxt
        # [String] $rs = $result.DocumentElement.OuterXml

        return $result.Envelope.Body

    } catch {
        $errorStatus = "Exception Message: " + $_.Exception.Message;
        Write-Host $errorStatus;
    }

}

Запрос информации об устройстве:

$tds_ip = "192.168.0.101"
$tds_port = "8899"


$reqBody = @"
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <GetDeviceInformation xmlns="http://www.onvif.org/ver10/device/wsdl"/>
  </s:Body>
</s:Envelope>
"@

$devInfoXml = Get-Onvif -tdsIP $tds_ip -tdsPort $tds_port -tdsBody $reqBody

Полученная информация:

PS C:\> $devInfoXml.GetDeviceInformationResponse


Manufacturer    : H264
Model           : HI3518E_53H13_S39
FirmwareVersion : V4.02.R12.00006531.10010.142100.ONVIF 2.4
SerialNumber    : b917a762682dc915
HardwareId      : 00001
#Получаем профили устройства
$reqBodyGetProfiles = @"
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <GetProfiles xmlns="http://www.onvif.org/ver10/media/wsdl"/>
  </s:Body>
</s:Envelope>
"@

$devProfilesXml = Get-Onvif -tdsIP $tds_ip -tdsPort $tds_port -tdsBody $reqBodyGetProfiles


#Тепреь можно получить URI снэпшота
$reqBodyGetSnapshotUri = @"
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <GetSnapshotUri xmlns="http://www.onvif.org/ver10/media/wsdl">
      <ProfileToken>000</ProfileToken>
    </GetSnapshotUri>
  </s:Body>
</s:Envelope>
"@

$devSnapshotXml = Get-Onvif -tdsIP $tds_ip -tdsPort $tds_port -tdsBody $reqBodyGetSnapshotUri

Делаем снимок камеры:

$snapshotUri = $devSnapshotXml.GetSnapshotUriResponse.MediaUri.Uri

Invoke-WebRequest $snapshotUri -OutFile c:\Temp\snapshot.jpg

Исправляем ошибку (включаем параметр useUnsafeHeaderParsing для Invoke-WebRequest):

$netAssembly = [Reflection.Assembly]::GetAssembly([System.Net.Configuration.SettingsSection])

if($netAssembly)
{
    $bindingFlags = [Reflection.BindingFlags] "Static,GetProperty,NonPublic"
    $settingsType = $netAssembly.GetType("System.Net.Configuration.SettingsSectionInternal")

    $instance = $settingsType.InvokeMember("Section", $bindingFlags, $null, $null, @())

    if($instance)
    {
        $bindingFlags = "NonPublic","Instance"
        $useUnsafeHeaderParsingField = $settingsType.GetField("useUnsafeHeaderParsing", $bindingFlags)

        if($useUnsafeHeaderParsingField)
        {
          $useUnsafeHeaderParsingField.SetValue($instance, $true)
        }
    }
}

Ссылки