Public/Set-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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#Requires -Modules 'MilestonePSTools'

function Set-ViewGroup {
<#
.SYNOPSIS
    Sets the properties of an existing 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' | Set-ViewGroup -Decription 'A new description'
    Gets the View Group(s) named 'Remote Guards' and sets the Description to 'A new description'
.OUTPUTS
    The output of this function when called with the -PassThru switch will be a
    [VideoOS.Management.VmoClient.PublicViewGroup] object with the following properties:
 
    Parent :
    Views : {}
    PublicViewGroups : {}
    Name :
    Description :
    CreatedDate : 1/1/0001 12:00:00 AM
    LastModified : 1/1/0001 12:00:00 AM
    Id : 00000000-0000-0000-0000-000000000000
    IsDirty : True
    IsCreated : False
    IsDeleted : False
    Exists : False
    CustomProperties : {}
    IsCustomPropertiesSupported : True
    ServerVersion : 20.3.1
    }
#>

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

        # Specifies the new name for the provided View Group
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [string]
        $Name,

        # Specifies the new description for the provided View Group
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [string]
        $Description,

        # Pass the updated viewgroup object to the pipeline
        [Parameter()]
        [switch]
        $PassThru
    )

    begin {
        $vmo = Get-VmoClient
    }

    process {
        try {
            if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Name')) {
                $ViewGroup.Name = $Name
            }
            if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Description')) {
                $ViewGroup.Description = $Description
            }

            if ($PSCmdlet.ShouldProcess("Public View Group '$($ViewGroup.Name)'", 'Update')) {
                $ViewGroup.Update()
            }

            if ($PassThru) {
                Write-Output $ViewGroup
            }
        }
        catch {
            $vmo.Dispose()
            throw
        }
    }

    end {
        $vmo.Dispose()
    }
}