Write-Host 'Setting SecurityProtocol to TLS 1.2 and greater' -ForegroundColor Green $protocol = [Net.SecurityProtocolType]::SystemDefault [enum]::GetNames([Net.SecurityProtocolType]) | Where-Object { # Match any TLS version greater than 1.1 ($_ -match 'Tls(\d)(\d+)?') -and ([version]("$($Matches[1]).$([int]$Matches[2])")) -gt 1.1 } | Foreach-Object { $protocol = $protocol -bor [Net.SecurityProtocolType]::$_ } [Net.ServicePointManager]::SecurityProtocol = $protocol if ($null -eq (Get-PackageSource -Name NuGet -ErrorAction Ignore)) { Write-Host 'Registering NuGet package source' -ForegroundColor Green $null = Register-PackageSource -Name NuGet -Location https://www.nuget.org/api/v2 -ProviderName NuGet -Trusted -Force } $nugetProvider = Get-PackageProvider -Name NuGet -ErrorAction Ignore $requiredVersion = [Microsoft.PackageManagement.Internal.Utility.Versions.FourPartVersion]::Parse('2.8.5.201') if ($null -eq $nugetProvider -or $nugetProvider.Version -lt $requiredVersion) { Write-Host 'Installing NuGet package provider' -ForegroundColor Green $null = Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force } if ($null -eq (Get-Module -ListAvailable PowerShellGet | Where-Object Version -ge 2.2.5)) { Write-Host 'Installing PowerShellGet 2.2.5 or greater' -ForegroundColor Green $null = Install-Module PowerShellGet -MinimumVersion 2.2.5 -Scope CurrentUser -AllowClobber -Force -ErrorAction Stop } Write-Host 'Installing MilestonePSTools' -ForegroundColor Green Install-Module MilestonePSTools -Scope AllUsers -Force -ErrorAction Stop -SkipPublisherCheck -AllowClobber Set-VmsModuleConfig -EnableTelemetry $false # Get Hardware from VMS $hardwarelist = Get-VmsCamera $ext = ".jpg" $time = (Get-Date).AddDays(-1).ToString("dddd, MMMM dd, yyyy 01:00:00 A\M") # Loop through the Cameralist foreach ($camera in $hardwarelist) { $file = $camera.Name + $ext try { if ($file -match "^(.*?-.*?)-") { $result = $matches[1] $path = "C:\snaps\" + $result If(!(test-path -PathType container $path)) { $null = New-Item -ItemType Directory -Path $path } } } catch { Write-Host "Failed to match pattern" } # Match HardwareID and make snapshot try { $null = Get-Snapshot -CameraId $camera.Id -Timestamp $time -Save -Path $path -Quality 100 -FileName $file Write-Host "Saving as:" $file } catch { Write-Host "Failed to fetch snapshot for Camera ID:" $camera.HardwareId } }