MilestoneSystemsInc / PowerShellSamples

A collection of samples for managing your Milestone XProtect VMS using MilestonePSTools in PowerShell
https://www.milestonepstools.com
MIT License
37 stars 12 forks source link

The term 'Set-VmsDeviceStorage' is not recognized as the name of a cmdlet #143

Closed aoforb closed 3 months ago

aoforb commented 3 months ago

Looks like the following command let is missing from the API. What other options do I have for setting the camera storage location?

Set-VmsDeviceStorage

image

aoforb commented 3 months ago

I guess my milestone PS tools version 23.3.1 is a little out dated now. Problem is getting the new version deployed to the sites over LTE. 300 x 70MB = 21GB

Can the storage location be set on version 23.3.1?

aoforb commented 3 months ago

Evening - does anyone know?

Thanks

joshooaj commented 3 months ago

Hi @aoforb,

I don't know if it's an option in your environment, but you can run the MilestonePSTools module on your local system instead of installing/copying it to the remote systems and run these commands over the air. That's only if you have remote access setup in some way (port forwarding, vpn, etc). Basically, if Smart Client or Management Client can login, so can MilestonePSTools.

Here's the content of the Set-VmsDeviceStorage command though in the event you can't run commands remotely. A lot of the commands in MilestonePSTools are written as PowerShell functions and can be seen in plain text in the MilestonePSTools.psm1 file for future reference.

function Set-VmsDeviceStorage {
    [CmdletBinding(SupportsShouldProcess)]
    [OutputType([VideoOS.Platform.ConfigurationItems.IConfigurationItem])]
    param (
        [Parameter(Mandatory, ValueFromPipeline)]
        [VideoOS.Platform.ConfigurationItems.IConfigurationItem[]]
        $Device,

        [Parameter(Mandatory)]
        [string]
        $Destination,

        [Parameter()]
        [switch]
        $PassThru
    )

    begin {
        Assert-VmsRequirementsMet -ErrorAction Stop
    }

    process {
        foreach ($currentDevice in $Device) {
            try {
                $taskInfo = $currentDevice.ChangeDeviceRecordingStorage()
                $itemSelection =  $taskInfo.ItemSelectionValues.GetEnumerator() | Where-Object { $_.Value -eq $Destination -or $_.Key -eq $Destination }
                if ($itemSelection.Count -eq 0) {
                    Write-Error -TargetObject $currentDevice "No storage destination available for device '$currentDevice' named '$Destination'" -RecommendedAction "Use one of the available destinations: $($taskInfo.ItemSelectionValues.Keys -join ', ')"
                    continue
                } elseif ($itemSelection.Count -gt 1) {
                    Write-Error -TargetObject $currentDevice "More than one storage destination matching '$Destination' for device '$currentDevice'." -RecommendedAction "Check your recording server storage configuration. The only way you should see this error is if a storage configuration display name matches a storage configuration ID on that recording server."
                    continue
                }

                if ($PSCmdlet.ShouldProcess($currentDevice, "Set storage to $($itemSelection.Key)")) {
                    $taskInfo.ItemSelection = $itemSelection.Value
                    $task = $taskInfo.ExecuteDefault()
                    $null = $task | Wait-VmsTask -Title "Change device recording storage: $currentDevice" -Cleanup
                    if ($PassThru) {
                        $currentDevice
                    }
                }
            } catch {
                Write-Error -TargetObject $currentDevice -Exception $_.Exception -Message $_.Exception.Message -Category $_.CategoryInfo.Category
            }
        }
    }
}