Created
July 29, 2019 17:26
-
-
Save joshooaj/a5456f88ade87ff62ff9cfd67e1a1ba2 to your computer and use it in GitHub Desktop.
MilestonePSTools Samples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 | |
} | |
## Change the Overall Security permissions for a role using Config API | |
$roleItem = $role | Get-ConfigurationItem | |
$task = $roleItem | Invoke-Method -MethodId ChangeOverallSecurityPermissions | |
# Uncomment to show all available security namespaces like Hardware, Camera, Microphone | |
# $task.Properties[0].ValueTypeInfos | Select-Object Name, Value | Format-Table | |
# We'll use the Camera namespace for this example | |
$task.Properties[0].Value = '623d03f8-c5d5-46bc-a2f4-4c03562d4f85' | |
$task = $task | Invoke-Method -MethodId ChangeOverallSecurityPermissions | |
# Uncomment to show all permissions available in this namespace | |
# $task.Properties | Where-Object Key -ne 'SecurityNamespace' | select DisplayName, Key, Value | Format-Table | |
# Set all permissions to 'Allow'. Other options are None and Deny | |
$task.Properties | Where-Object Key -ne 'SecurityNamespace' | Foreach-Object { | |
$_.Value = 'Allow' | |
} | |
$result = $task | Invoke-Method -MethodId ChangeOverallSecurityPermissions | |
## Create a new Storage Configuration with Archive | |
$rec = Get-RecordingServer | |
$path = "C:\MediaDatabase" | |
$useSigning = $false | |
$retentionMinutes = 24*60 | |
$maxSizeInMB = 512GB / 1024 / 1024 | |
try { | |
$result = $rec.StorageFolder.AddStorage("StorageName", "StorageDescription", $path, $useSigning, $retentionMinutes, $maxSizeInMB) | |
if ($result.State -eq "Success") { | |
$newStorage = $rec.StorageFolder.Storages | Where-Object Path -eq $result.Path | |
$targetFrameRate = 30 | |
$archiveMinutes = 30*24*60 | |
$maxArchiveSizeInMB = 10TB / 1024 / 1024 | |
$result = $newStorage.ArchiveStorageFolder.AddArchiveStorage("Name", "Description", $path, $targetFrameRate, $archiveMinutes, $maxArchiveSizeInMB) | |
if ($result.State -eq "Success") { | |
$newStorage | |
} else { | |
throw $result.ErrorText | |
} | |
} else { | |
throw $result.ErrorText | |
} | |
} catch { | |
Write-Error $_.Exception.Message | |
} | |
## Change the storage for all cameras attached to a given Hardware device | |
$hardware | Get-Camera | ForEach-Object { | |
try { | |
$moveRecordings = $false | |
$task = $_.ChangeDeviceRecordingStorage($newStorage.Path, $moveRecordings) | |
while ($true) { | |
Write-Output "Changing $($_.Name)" | |
$task = $task | Get-ConfigurationItem | |
$state = $task.Properties | Where-Object Key -eq "State" | |
if ($state.Value -eq "Completed") { | |
break | |
} | |
Start-Sleep -Seconds 0.2 | |
} | |
} catch { | |
throw | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment