Skip to content

Instantly share code, notes, and snippets.

View joshooaj's full-sized avatar

Josh Hendricks joshooaj

View GitHub Profile
@joshooaj
joshooaj / Get-VmsConfigPassword.ps1
Last active September 21, 2021 16:32
Reads the system configuration password from disk. This password is used to protect the key in the SQL database which is used to protect sensitive data like device passwords.
function Get-VmsConfigPassword {
<#
.SYNOPSIS
Reads the Milestone XProtect Advanced VMS configuration password
.DESCRIPTION
The configuration password is used to securely encrypt a unique
encryption key in the Surveillance SQL database. This encryption key is
used to protect sensitive data such as camera credentials and licensing
data. To protect this encryption key, a configuration password can be
set by the admin. Here's how the configuration password is used:
@joshooaj
joshooaj / Set-CertKeyPermission.ps1
Created September 22, 2021 16:48
Locates the private key on the file system and updates permissions
function Set-CertKeyPermission {
[CmdletBinding(SupportsShouldProcess)]
param(
# Specifies the certificate store path to locate the certificate specified in Thumbprint. Example: Cert:\LocalMachine\My
[Parameter()]
[string]
$CertificateStore = 'Cert:\LocalMachine\My',
# Specifies the thumbprint of the certificate to which private key access should be updated.
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
@joshooaj
joshooaj / Trace-VmsAlarms.ps1
Created September 22, 2021 21:49
Listens for new alarms from a Milestone XProtect VMS installation
function Trace-VmsAlarms {
<#
.SYNOPSIS
Polls a Milestone XProtect Event Server for new alarmline entries
.DESCRIPTION
Starts a polling loop to ask for new alarmline entries from a Milestone XProtect Event
Server. The InitialStartTime is "now" by default, so only new alarms are returned. You
can either pipe the alarms to a Foreach-Object and process them there, or provide a
scriptblock which will be invoked once for each alarm returned.
.EXAMPLE
@joshooaj
joshooaj / Expand-IPRange.ps1
Last active September 28, 2021 12:28
Expands a start and end IP address into an array of IP addresses within the given range.
class CidrInfo {
[string] $Cidr
[IPAddress] $Address
[int] $Mask
[IPAddress] $Start
[IPAddress] $End
[IPAddress] $SubnetMask
[IPAddress] $HostMask
@joshooaj
joshooaj / Sample-Camera-Storage-Report.ps1
Created September 30, 2021 22:17
Returns all cameras from all Milestone XProtect sites in a federated hierarchy with their recording path, and the recording server and site names where the cameras are located.
$loginSettings = Get-LoginSettings
Get-Site -ListAvailable | Where-Object { $_.FQID.ServerId.Id -in $loginSettings.Guid } | Foreach-Object {
$site = $_
$site | Select-Site
$storageMap = @{}
Get-RecordingServer | Foreach-Object {
$rec = $_
$rec.StorageFolder.Storages | ForEach-Object { $storageMap.($_.Path) = $_.DiskPath }
$rec | Get-Hardware | Foreach-Object {
$hw = $_
@joshooaj
joshooaj / Get-VmsStorageRetention.ps1
Last active September 30, 2021 22:30
Gets a [timespan] representing the storage retention for the specified Milestone XProtect recording server storage configuration
function Get-VmsStorageRetention {
<#
.SYNOPSIS
Gets a [timespan] representing the storage retention for the specified storage configuration
.DESCRIPTION
A Milestone Storage object represents both the overall storage configuration and the live
storage information for that storage configuration. It has ArchiveStorage child items for each
archive path associated with that storage configuration. To determine the retention for the
whole storage configuration, you need to find the largest "RetainMinutes" value between the
@joshooaj
joshooaj / profile.ps1
Last active October 9, 2021 16:11
My hosts file display and manipulation functions for my profile script
class HostsFileEntry {
[IPAddress] $IP
[string[]] $Hosts
[string] ToString() {
return "$($this.IP) $([string]::Join(' ', $this.Hosts))"
}
}
function Get-HostsFileEntry {
@joshooaj
joshooaj / Get-PlaybackInfo2.ps1
Created October 17, 2021 21:01
A potential replacement for Get-PlaybackInfo which in limited testing is 249% faster by using a SequenceDataSource instead of a RawDataSource.
function Get-PlaybackInfo2 {
[CmdletBinding()]
param (
# Accepts a Milestone Configuration Item path string like Camera[A64740CF-5511-4957-9356-2922A25FF752]
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName, ParameterSetName = 'FromPath')]
[ValidateScript( {
if ($_ -notmatch '^(?<ItemType>\w+)\[(?<Id>[a-fA-F0-9\-]{36})\]$') {
throw "$_ does not a valid Milestone Configuration API Item path"
}
if ($Matches.ItemType -notin @('Camera', 'Microphone', 'Speaker', 'Metadata')) {
@joshooaj
joshooaj / Register-VmsServer.ps1
Last active November 18, 2021 07:02
Run Milestone Server Configurator silently on a remote system to register with a Milestone XProtect Management Server
function Register-VmsServer {
<#
.SYNOPSIS
Performs the registration of all Milestone services on the targetted computer.
.DESCRIPTION
The Milestone Server Configurator utility, from version 2020 R3, provides a
command-line interface (CLI) supporting the registration of services to a
specified management server.
@joshooaj
joshooaj / Get-HardwarePasswordReport.ps1
Created December 1, 2021 16:19
Generate a report of all passwords for all cameras on your Milestone XProtect VMS.
# This is an example function showing how you might use the Get-HardwarePassword cmdlet
# to retrieve passwords for camera hardware objects.
function Get-HardwarePasswordReport {
[CmdletBinding()]
param (
# Optionally specify one or more recording servers from which to report hardware passwords
[Parameter()]
[VideoOS.Platform.ConfigurationItems.RecordingServer[]]
$RecordingServer
)