Skip to content

Instantly share code, notes, and snippets.

@joshooaj
Created September 5, 2019 17:24
Show Gist options
  • Save joshooaj/ffd8c915c628c1655ff73236d6608e35 to your computer and use it in GitHub Desktop.
Save joshooaj/ffd8c915c628c1655ff73236d6608e35 to your computer and use it in GitHub Desktop.
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)
}
return $text
}
function ReplaceInvalidPathChars {
param(
[string]
$text,
[string]
$substition
)
foreach ($c in [System.IO.Path]::GetInvalidPathChars()) {
$text = $text.Replace($c, $substition)
}
return $text
}
Connect-ManagementServer
foreach ($recorder in Get-RecordingServer) {
$cameras = $recorder | Get-Hardware | Where-Object Enabled |
Get-Camera | Where-Object Enabled
foreach ($camera in $cameras) {
$fileName = ReplaceInvalidFilenameChars "$($camera.Name).jpg" "-"
$path = ReplaceInvalidPathChars "C:\snapshots\$($recorder.Name)" "-"
if (-not (Test-Path $path)) {
New-Item $path -ItemType Directory
}
$camera | Get-Snapshot -Path $path -FileName $fileName -Live -Save
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment