Public/Remove-ViewGroup.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#Requires -Modules 'MilestonePSTools'

function Remove-ViewGroup {
<#
.SYNOPSIS
    Removes an existing View Group and all the views and groups present within that View Group
.DESCRIPTION
    Working with View Groups is not currently supported in MIP SDK, however the redistributable SDK
    includes an assembly containing the VmoClient which is a component used internally by the SDK
    and applications like XProtect Management Client.
 
    This function makes use of this VmoClient to manipulate the View Groups to enable complex tasks
    required in some environments.
.EXAMPLE
    PS C:\> Get-ViewGroup -Name 'Remote Guards' | Remove-ViewGroup
    Gets the View Group(s) named 'Remote Guards' and removes (deletes) them from the Management Server, including all views contained within.
#>

    [CmdletBinding(ConfirmImpact='High', SupportsShouldProcess)]
    param(
        # Specifies the View Group object to be deleted
        [Parameter(Mandatory, ValueFromPipeline)]
        [ValidateNotNullOrEmpty()]
        [VideoOS.Management.VmoClient.PublicViewGroup]
        $ViewGroup
    )

    begin {
        $vmo = Get-VmoClient
    }

    process {
        try {
            if ($PSCmdlet.ShouldProcess("Public View Group '$($ViewGroup.Name)'", 'Remove')) {
                $ViewGroup.Delete()
            }
        }
        catch {
            $vmo.Dispose()
            throw
        }
    }

    end {
        $vmo.Dispose()
    }
}