Skip to content

Instantly share code, notes, and snippets.

@joshooaj
Last active January 31, 2024 23:42
Show Gist options
  • Save joshooaj/329d794b62c76c535acd3d363588f2f4 to your computer and use it in GitHub Desktop.
Save joshooaj/329d794b62c76c535acd3d363588f2f4 to your computer and use it in GitHub Desktop.
Import hardware in Milestone XProtect from a Lenel CSV file
# Copyright (c) Milestone Systems A/S.
# Licensed under the MIT License.
function ConvertFrom-LenelCsv {
<#
.SYNOPSIS
Convert a CSV export from from Lenel's migration tool into a CSV format for MilestonePSTools.
.DESCRIPTION
The `ConvertFrom-LenelCsv` cmdlet converts a CSV file created using Lenel's migration tool into a CSV format
compatible with the `Import-VmsHardware` cmdlet in the MilestonePSTools module.
The data available in the Lenel CSV file does not include camera credentials, driver number, or the destination
recording server display name, so this information will need to be added/changed before using `Import-VmsHardware`.
.PARAMETER Path
Specifies the path to the CSV file produced by the Lenel Migration Tool.
.PARAMETER Destination
Specifies the path and file name of the destination CSV file to be used with the `Import-VmsHardware` cmdlet.
.EXAMPLE
ConvertFrom-LenelCsv -Path .\LNVR_Details.csv -Destination .\vms-hardware.csv
# Edit the new vms-hardware.csv file with the necessary camera credentials and recording server names
Import-VmsHardware -Path .\vms-hardware.csv
Converts the Lenel-formatted CSV file exported by the Lenel Migration Tool into a format compatible with the
Import-VmsHardware cmdlet from the MilestonePSTools module, then uses that cmdlet to import the cameras in Milestone.
.NOTES
The columns in the resulting CSV file with header names beginning with "LNVR_" are not used by MilestonePSTools and
will not be imported. You may choose to write your own script to further configure the imported hardware.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$Path,
[Parameter(Mandatory)]
[string]
$Destination
)
process {
$lastLnvrServer = $null
$includedColumns = '*', @{ Name = 'LNVR'; Expression = { $lastLnvrServer } }
$excludedColumns = 'Name', 'MigrationStatus', 'LNVR', 'XProtectRecorder', 'CommunicationServer', 'LNVRStatus'
$lnvrCams = Import-Csv -Path $Path -ErrorAction Stop | ForEach-Object {
if ([string]::IsNullOrWhiteSpace($_.CameraName)) {
if ([string]::IsNullOrWhiteSpace($_.LNVR)) {
throw 'Expected a value in the LNVR column but found a null or empty string.'
}
$lastLnvrServer = "$($_.LNVR)".Trim()
} else {
$_ | Select-Object $includedColumns -ExcludeProperty $excludedColumns
}
}
$lnvrCams | Group-Object IPAddress | ForEach-Object {
$ip = $_.Name
$cameras = $_.Group
[pscustomobject]@{
Address = [uri]('http://{0}' -f $ip)
UserName = $null
Password = $null
DriverNumber = $null
# Use the first word in the CamerType field as the driver family as a best effort. This may not match the available driver groups in Milestone and may need to be modified or removed.
DriverFamily = $cameras[0].CameraType -split '\s' | Select-Object -First 1
StorageName = $null
HardwareName = '{0} ({1})' -f $cameras[0].CameraType, $ip
Coordinates = $null
CameraName = $cameras.CameraName -join ';'
MicrophoneName = $null
SpeakerName = $null
MetadataName = $null
InputName = $null
OutputName = $null
EnabledCameraChannels = 0..($cameras.Count - 1) -join ';'
EnabledMicrophoneChannels = $null
EnabledSpeakerChannels = $null
EnabledMetadataChannels = $null
EnabledInputChannels = $null
EnabledOutputChannels = $null
CameraGroup = $null
MicrophoneGroup = $null
SpeakerGroup = $null
MetadataGroup = $null
InputGroup = $null
OutputGroup = $null
RecordingServer = $cameras[0].LNVR
UseDefaultCredentials = $false
Description = $null
LNVR_CameraAudio = $cameras.CameraAudio -join ';'
LNVR_CameraFrameRate = $cameras.CameraFrameRate -join ';'
LNVR_CameraCodec = $cameras.CameraCodec -join ';'
LNVR_CameraCompression = $cameras.CameraCompression -join ';'
}
} | Export-Csv -Path $Destination -NoTypeInformation
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment