A collection of sample scripts to bootstrap your Milestone XProtect VMS Management Adventure
Explore the samples »
Report Bug
·
Request Feature
This repository contains sample PowerShell scripts for managing and automating tasks related to Milestone XProtect VMS software using MilestonePSTools. It is intended to be a supplement to the built-in documentation available in many cmdlets within MilestonePSTools which you can access using Get-Help
.
[]()
In order to make the most out of MilestonePSTools you will need at least some basic familiarity with PowerShell or other shells. It's possible to perform very basic actions in a few lines of PowerShell with limited experience. With a bit more experience and ambition, it's also possible to develop extensive and powerfull tools or entire modules to automate important business and maintenance tasks unique to your organization.
If you're new to PowerShell, there are a wide range of resources available to learn. One popular example is the Learn Windows PowerShell in a Month of Lunches series which, while last updated in 2014, is still a good resource for picking up the syntax and style.
MilestonePSTools is developed using the latest build of Milestone's MIP SDK. As such, it has the following prerequisits:
$PSVersionTable
to determine the PSVersion of your current PowerShell terminal. If you need to upgrade PowerShell, download Windows Management Framework 5.1 from Microsoft.You can install MilestonePSTools on the computer where your Milestone VMS is installed, but that is not required. In fact, from a security standpoint it is best to avoid installing software on the same server as your VMS if it's not necessary. Just as the XProtect Smart Client and Management Client may be used from a networked PC, so too can MilestonePSTools be used from a remote system.
You can copy & paste the script below into a PowerShell prompt, or PowerShell ISE, and as long as you have PowerShell 5.1 installed, it should get you up and running.
$script = @"
Write-Host 'Setting SecurityProtocol to TLS 1.2, Execution Policy to RemoteSigned' -ForegroundColor Green
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Confirm:`$false -Force
Write-Host 'Registering the NuGet package source if necessary' -ForegroundColor Green
if (`$null -eq (Get-PackageSource -Name NuGet -ErrorAction Ignore)) {
`$null = Register-PackageSource -Name NuGet -Location https://www.nuget.org/api/v2 -ProviderName NuGet -Trusted -Force
}
Write-Host 'Installing the NuGet package provider' -ForegroundColor Green
`$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) {
`$null = Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
}
Write-Host 'Setting PSGallery as a trusted repository' -ForegroundColor Green
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Write-Host 'Installing PowerShellGet 2.2.5 or greater if necessary' -ForegroundColor Green
if (`$null -eq (Get-Module -ListAvailable PowerShellGet | Where-Object Version -ge 2.2.5)) {
`$null = Install-Module PowerShellGet -MinimumVersion 2.2.5 -Force
}
Write-Host 'Installing or updating MilestonePSTools' -ForegroundColor Green
if (`$null -eq (Get-Module -ListAvailable MilestonePSTools)) {
Install-Module MilestonePSTools
}
else {
Update-Module MilestonePSTools
}
"@
Start-Process -FilePath powershell.exe -ArgumentList "-Command $script" -Verb RunAs
The script above may look intimidating, and you should never copy and paste code of any kind if you don't know what it does. In short, the script is designed to make it as easy and fast as possible to get MilestonePSTools installed. Sometimes your PowerShell environment needs a few adjustments and updates to be able to install PowerShell modules. Let's break down what this actually does, just in case your boss asks!
RemoteSigned
. The default on Windows 10 is Restricted
and that will prevent you from actually using any PowerShell modules. RemoteSigned
means any scripts that are "blocked" must be signed.C:\Program Files\WindowsPowerShell\Modules\
Connect-Vms -AcceptEula
Connect-Vms -Name 'MyVMS'
Connect-Vms -Name 'MyVMS' -ServerAddress 'http://MyVMS' -Credential (Get-Credential)
Connect-Vms -Name 'MyVMS' -ShowDialog
Connect-Vms -ServerAddress 'http://MyVMS' -Credential (Get-Credential) -BasicUser
# Slower but uses Configuration API so each object can be used to modify configuration
Get-VmsCamera | Select Name
# Faster but provides limited access to camera properties and Items cannot be used to
# modify configuration
Get-PlatformItem -Kind (Get-Kind -List | ? DisplayName -eq Camera).Kind | Select Name
Using Add-Hardware
# Select a Recording Server by name
$recorder = Get-VmsRecordingServer -Name Artemis
# Add a StableFPS device (if the driver is installed) using the default hardware name
$hardware1 = Add-VmsHardware -RecordingServer $recorder -HardwareAddress http://192.168.1.101:1001 -Credential (Get-Credential) -DriverNumber 5000
# Add a camera without specifying the driver and name it 'New Hardware'
$hardware2 = Add-VmsHardware -RecordingServer $recorder -Name 'New Hardware' -Address http://192.168.1.102 -UserName root -Password notpass
# Enable all camera channels on $hardware2
foreach ($camera in $hardware2 | Get-VmsCamera) {
$camera | Set-VmsCamera -Enabled $true
}
Using Import-HardwareCsv\ hardware.csv
"HardwareName","HardwareAddress","UserName","Password"
"Reception","http://192.168.1.102","root","notpass"
"Shipping","http://192.168.1.103","root","notpass"
"Parking","http://192.168.1.104","root","notpass"
$recorder = Get-VmsRecordingServer -Name Artemis
Import-VmsHardware -Path hardware.csv -RecordingServer $recorder
$cameras = Get-VmsCamera
foreach ($camera in $cameras) {
$null = Get-Snapshot -Camera $camera -Live -Save -Path C:\demo\snapshots -UseFriendlyName -LocalTimestamp
}
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)Distributed under the MIT License. See LICENSE
for more information.
Josh Hendricks - LinkedIn - jh@milestonesys.com