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:
- Milestone XProtect VMS (XProtect Essential+, Express+, Professional+, Expert, or Corporate) 2014 or newer
- Windows Desktop/Server edition (not compatible with PowerShell Core)
- .NET Framework 4.7
- PowerShell 5.1. Use
$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!
- A script is launched in a new PowerShell instance requiring elevation
- Sets the HTTPS security protocol to TLS 1.2 which is required for communicating with PSGallery
- Sets the execution policy to
RemoteSigned
. The default on Windows 10 isRestricted
and that will prevent you from actually using any PowerShell modules.RemoteSigned
means any scripts that are "blocked" must be signed. - Registers NuGet.org as a package source. This is not strictly necessary, but can be useful if you need to install .NET packages from PowerShell, and in the future we may update MilestonePSTools to depend on the official MIP SDK NuGet packages.
- Installs the NuGet package provider which is used by PowerShellGet as a source for installing PowerShell modules. You may have an older version of PowerShellGet so this will ensure it gets updated.
- Sets the PSGallery repository as a trusted source for PowerShell modules. This is not mandatory but will prevent you from having to acknowledge each module you install.
- Updates to the latest PowerShellGet module
- Installs/updates MilestonePSTools to
C:\Program Files\WindowsPowerShell\Modules\
- Connect with the current Windows user
Connect-ManagementServer -Server myvms -AcceptEula
- Connect with a Windows or Active Directory user
Connect-ManagementServer -Server myvms -Credential (Get-Credential) -AcceptEula
- Connect with a Milestone Basic User
Connect-ManagementServer -Server myvms -Credential (Get-Credential) -BasicUser -AcceptEula
# Slower but uses Configuration API so each object can be used to modify configuration
Get-Hardware | Where-Object Enabled | Get-Camera | Where-Object Enabled | 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-RecordingServer -Name Artemis # Add a StableFPS device (if the driver is installed) using the default hardware name $hardware1 = Add-Hardware -RecordingServer $recorder -Address http://192.168.1.101:1001 -UseDefaultCredentials -DriverId 5000 -GroupPath /StableFPS # Add a camera without specifying the driver, name it 'New Camera' and place it in a Camera Group named 'New Cameras' $hardware2 = Add-Hardware -RecordingServer $recorder -Name 'New Camera' -Address http://192.168.1.102 -UserName root -Password notpass -GroupPath '/New Cameras' # Enable all camera channels on $hardware2 foreach ($camera in $hardware2 | Get-Camera) { $camera.Enabled = $true $camera.Save() }
-
Using Import-HardwareCsv
hardware.csv"HardwareName","HardwareAddress","UserName","Password" "Reception","https://192.168.1.102","root","notpass" "Shipping","https://192.168.1.103","root","notpass" "Parking","https://192.168.1.104","root","notpass"
$recorder = Get-RecordingServer -Name Artemis Import-HardwareCsv -Path hardware.csv -RecordingServer $recorder
$cameras = Get-Hardware | ? Enabled | Get-Camera | ? Enabled
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.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Josh Hendricks - LinkedIn - [email protected]