Scripts/Switch-iSpyAgentCameraOff.ps1
Function Switch-iSpyAgentCameraOff { <# .SYNOPSIS Turn selected camera off .DESCRIPTION Turn selected camera off .PARAMETER iSpyHost Computer name or IP (optional, default = LOCALHOST) .PARAMETER Port Port number to access AgentDVR (optional, default = 8090) .PARAMETER CameraId The Id of the camera to turn off .PARAMETER Type Type of object: Camera, Mic (optional, default = Camera) .EXAMPLE Switch-iSpyAgentCameraOff -iSpyHost MyCamsSystem -CameraId 1 .EXAMPLE Switch-iSpyAgentCameraOff -iSpyHost 192.168.10.20 -CameraId 1 -Type Mic .EXAMPLE Switch-iSpyAgentCameraOff -iSpyHost MyCamsSystem -CameraId 1, 2, 3, 4 .EXAMPLE Switch-iSpyAgentCameraOff -iSpyHost 192.168.10.20 -CameraId 1, 2, 3, 4 .NOTES More than 1 CameraId can be entered, values must be seperated by commas .LINK N/A #> [CmdletBinding ()] Param ( [Parameter (Mandatory = $False, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, HelpMessage = 'Enter computer name or IP' ) ] [String]$iSpyHost = 'localhost', [Parameter (Mandatory = $False, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, HelpMessage = 'Enter port number' ) ] [String]$Port = '8090', [Parameter (Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, HelpMessage = 'Enter camera Id' ) ] [String[]]$CameraId, [Parameter (Mandatory = $False, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, HelpMessage = 'Enter type' ) ] [ValidateSet ('Camera', 'Mic')] [String]$Type = 'Camera' ) BEGIN { Function Show-Output ($Values) { [PSCustomObject]@{ iSpyHost = $Values[0] Status = $Values[1] } } } PROCESS { Show-ProgressBar -Activity 'iSpy Agent DVR' -TotalItems 1 -Counter 1 -ProcessItem $iSpyHost.ToUpper() If (Test-Connection -ComputerName $iSpyHost -Count 1 -Quiet) { $iSpyHostURL = -join ('http://', $iSpyHost, ":$Port") ForEach ($Camera In $CameraId) { Try { Switch ($Type) { 'Mic' { $pIndex = 1 } 'Camera' { $pIndex = 2 } } $Results = Invoke-WebRequest -Uri "$iSpyHostURL/Command/SwitchOff?OId=$Camera&OT=$pIndex" | ConvertFrom-Json If ($Results.Status.toUpper() -eq 'OK') { $Status = -join ('Camera ', $Camera, ' Off') } Else { $Status = $Results.Status.toUpper() } Show-Output ($iSpyHost.ToUpper(), $Status) } Catch { Show-Output ($iSpyHost.ToUpper(), $PSItem.Exception.Message) } } } Else { Show-Output ($iSpyHost.ToUpper(), 'Unreachable') } } END {} } |