Skip to content

Instantly share code, notes, and snippets.

View joshooaj's full-sized avatar

Josh Hendricks joshooaj

View GitHub Profile
@joshooaj
joshooaj / Measure-SequenceData.ps1
Created October 29, 2020 00:03
Generate an interval report of sorts, showing the amount of time motion was detected and video was recorded for a given camera over a period of time, split into a given interval of time.
function Measure-SequenceData {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[VideoOS.Platform.ConfigurationItems.Camera]
$Camera,
[Parameter()]
[DateTime]
$Start = [DateTime]::MinValue,
@joshooaj
joshooaj / ViewGroupFunctions.ps1
Created January 22, 2021 01:05
Functions for working with View Groups in Milestone
#Requires -Modules 'MilestonePSTools'
function Get-ViewGroup {
<#
.SYNOPSIS
Removes an existing View Group and all the views and groups present within that View Group
.DESCRIPTION
Working with View Groups is not currently supported in MIP SDK, however the redistributable SDK
includes an assembly containing the VmoClient which is a component used internally by the SDK
and applications like XProtect Management Client.
@joshooaj
joshooaj / Test-MediaDbBank.ps1
Created January 29, 2021 18:16
Test-MediaDBBank
function Find-MediaDb {
$config = [xml](Get-Content 'C:\ProgramData\Milestone\XProtect Recording Server\Offline\ConfigurationDataset.xml')
Write-Output $config.Cache.ConfigurationDataSet.RecordingStorage
Write-Output $config.Cache.ConfigurationDataSet.ArchiveStorage
}
function Test-Xml {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
@joshooaj
joshooaj / Set-MotionDetection.ps1
Created January 30, 2021 00:55
Wrote up a function this afternoon to make it quicker and easier to modify motion detection settings for a camera. Might just refactor it a little and include it in MilestonePSTools later.
function Set-MotionDetection {
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='High')]
param(
[Parameter(Mandatory, ValueFromPipeline)]
[VideoOS.Platform.ConfigurationItems.Camera]
$Camera,
[Parameter()]
[switch]
@joshooaj
joshooaj / Find-UnmappedCameras.ps1
Last active May 12, 2022 22:39
A quick and dirty script to see which cameras are not already added to a map using the old non-GIS based mapping feature. This requires access to SQL since the SDK does not provide access to the map XML.
# This script requires the sqlserver module and milestonepstools
# Instead of using the #Requires -Modules ... directive, we'll check for the presence
# of the modules and install them in CurrentUser scope automatically. This way
# the script can be copied and pasted, or downloaded and executed.
foreach ($module in 'sqlserver', 'milestonepstools') {
if ($null -eq (Get-Module $module -ListAvailable -ErrorAction Ignore)) {
Install-Module -Name $module -Scope CurrentUser -Force -Confirm:$false -SkipPublisherCheck -AllowClobber -ErrorAction Stop
}
}
@joshooaj
joshooaj / DeviceGroupReport.ps1
Created April 16, 2021 19:18
Enumerate all device groups recursively and build up a hashtable object with the details about the device groups on the system, and all the devices added to those device groups.
# Generic function which can take a device group from Get-DeviceGroup and go backwards to determine the full hierarchy of the device group path.
function Resolve-DeviceGroupPath {
[CmdletBinding()]
param(
[Parameter(Mandatory, ValueFromPipeline)]
[VideoOS.Platform.ConfigurationItems.IConfigurationItem]
$DeviceGroup
)
process {
@joshooaj
joshooaj / Copy-ViewGroups.ps1
Last active April 19, 2021 23:41
Copy all view groups and their contents from child sites up to the parent site
#Requires -Modules MilestonePSTools, MilestonePSTools.ViewGroups
<#
This sample shows how you could copy all view groups defined in child sites within a Milestone Federated Hierarchy up to the parent
site. This way local users can login to their child-site directly, and create/use views defined there, and users logging in to the
parent site can get a copy of those same views.
With only a little more effort, this could be setup as a scheduled task to run daily to keep views at the parent site in sync with
the child sites.
@joshooaj
joshooaj / Windows-NTP-Functions.ps1
Created April 23, 2021 14:35
A few functions to help configure NTP settings in windows
function Set-NtpServer {
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string[]]
$Source
)
process {
@joshooaj
joshooaj / Get-DeviceStatusReport.ps1
Created May 23, 2021 18:07
Get current device status for all cameras from all recording servers and produce a table of Recording Servers with the number of cameras having errors
function Get-DeviceStatusReport {
$cameraKind = Get-Kind -List | Where-Object DisplayName -eq 'Camera' | Select-Object -ExpandProperty Kind
$groupedCameras = Get-PlatformItem -Kind $cameraKind | Select-Object @{Name='RecorderId'; Expression={$_.FQID.ServerId.Id}}, @{Name='CameraId'; Expression={$_.FQID.ObjectId}} | Group-Object RecorderId
foreach ($group in $groupedCameras) {
$recorder = Get-RecordingServer -Id $group.Name
try {
$svc = Get-RecorderStatusService2 -RecordingServer $recorder
$cameraStatusArray = $svc.GetCurrentDeviceStatus((Get-Token), $group.Group.CameraId).CameraDeviceStatusArray
[pscustomobject]@{
Recorder = $recorder.Name
@joshooaj
joshooaj / Get-VmsDeviceStatistics.ps1
Created May 24, 2021 22:58
Uses RecorderStatusService2 interface to pull camera statistics from the Recording Server(s)
function Get-VmsDeviceStatistics {
[CmdletBinding()]
param(
# Specifies the Recording Server from which to return all available camera statistics.
[Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'PerRecorder')]
[VideoOS.Platform.ConfigurationItems.RecordingServer]
$RecordingServer,
# Specifies a Camera object from Get-Camera. The Recording Server will be discovered from the Camera object, and statistics will be returned for the one device.
[Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'PerCamera')]