Skip to content

Instantly share code, notes, and snippets.

View joshooaj's full-sized avatar

Josh Hendricks joshooaj

View GitHub Profile
@joshooaj
joshooaj / MilestonePSTools_readme.md
Created June 19, 2019 18:12
MilestonePSTools Examples

MilestonePSTools PowerShell Module

Description

MilestonePSTools is my (Josh Hendricks) side project exploring the various ways PowerShell can be used to enable automation and overall enhance the experience of configuring or querying a Milestone XProtect VMS environment. This module is written in C# and is effectively a PowerShell-friendly wrapper around Milestone's MIP SDK.

There is nothing in this module that is not possible to build using the .NET components from the MIP SDK directly in your scripts, but doing so quickly becomes complicated, and difficult to maintain. This was my experience when exploring writing PS1 scripts where I imported MIP SDK dll's directly into my scripts, handled authentication and .NET object instantiation for

@joshooaj
joshooaj / GetRecordedSnapshot.cs
Created July 27, 2019 09:11
Snippet of MilestonePSTools Get-Snapshot command source code
private void GetRecordedSnapshot()
{
JPEGVideoSource src = null;
var cameraId = Camera == null ? CameraId : new Guid(Camera.Id);
try
{
var item = Configuration.Instance.GetItem(Connection.CurrentSite.FQID.ServerId, cameraId, Kind.Camera);
if (item == null)
{
WriteWarning($"Configuration not available for camera with ID {cameraId}. It might be disabled.");
@joshooaj
joshooaj / Examples.ps1
Created July 29, 2019 17:26
MilestonePSTools Samples
## Create a basic user and add it to a role
$ms = Get-ManagementServer
$role = Get-Role -Name "MyUsers"
$result = $ms.BasicUserFolder.AddBasicUser("User1", "Suitable description", "S3cretP@sscode")
if ($result.State -eq "Success") {
$user = $ms.BasicUserFolder.BasicUsers | Where-Object Path -eq $result.Path
$role | Add-User -Sid $user.Sid
} else {
Write-Error $result.ErrorText
@joshooaj
joshooaj / GetPlaybackInfo.cs
Created September 3, 2019 19:50
MilestonePSTools Get-PlaybackInfo
using System;
using System.Linq;
using System.Management.Automation;
using VideoOS.Platform;
using VideoOS.Platform.ConfigurationItems;
using VideoOS.Platform.Data;
namespace MilestonePSTools.SnapshotCommands
{
/// <summary>
@joshooaj
joshooaj / SaveSnapshots.ps1
Created September 5, 2019 17:24
MilestonePSTools snapshot example for IPVM forum post
function ReplaceInvalidFilenameChars {
param(
[string]
$text,
[string]
$substition
)
foreach ($c in [System.IO.Path]::GetInvalidFileNameChars()) {
$text = $text.Replace($c, $substition)
@joshooaj
joshooaj / RequestAndInstallCertificate.ps1
Created October 9, 2019 23:52
Request a CA certificate using the WebServer template and configure Recording Server to use it to secure client connections
function Set-CertificatePermission {
[CmdletBinding()]
param(
[string]
$CertificatePath,
[string]
$UserName,
[string]
$Permission
)
@joshooaj
joshooaj / StreamReceiver.cs
Created February 19, 2020 14:57
An example of a live stream retriever for Milestone MIP SDK
using System;
using System.Threading;
using VideoOS.Platform;
using VideoOS.Platform.Live;
namespace SampleSnapshotService
{
public class StreamReceiver : IDisposable
{
private readonly Item _item;
@joshooaj
joshooaj / GetBookmark.cs
Created September 8, 2020 19:27
Get-Bookmark implementation
using System;
using System.Management.Automation;
using VideoOS.Common.Proxy.Server.WCF;
namespace MilestonePSTools.BookmarkCommands
{
/// <summary>
/// <para type="synopsis">Gets one or more bookmarks based on the supplied parameters</para>
/// <para type="description">Gets all bookmarks matching the supplied parameters. If there is any
/// overlap between the timespan represented by the StartTime and EndTime parameters, and the
@joshooaj
joshooaj / Import-DOTCameras.ps1
Created September 11, 2020 00:04
A couple of functions to import Oregon and Washington DOT traffic cameras with GPS coordinates into Milestone
function Import-TripCheck {
[CmdletBinding()]
param(
[Parameter(Mandatory, ValueFromPipeline)]
[VideoOS.Platform.ConfigurationItems.RecordingServer]
$Recorder,
[Parameter(Mandatory)]
[string]
$ApiKey,
@joshooaj
joshooaj / New-Timelapse.ps1
Last active March 19, 2024 13:36
Create a timelapse video using MilestonePSTools to retrieve jpegs from a Milestone VMS and ffmpeg to compile those snapshots into an h264 timelapse video
function New-Timelapse {
<#
.SYNOPSIS
Exports still images from XProtect and creates a timelapse video using ffmpeg.
.DESCRIPTION
This example function saves jpeg images from the recordings of the specified
camera to a temp folder, and uses these images as input to the ffmpeg
command-line utility to generate a timelapse video from the images.