Public/Get-bConnectDynamicGroup.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
Function Get-bConnectDynamicGroup() {
    <#
        .Synopsis
            Get specified Dynamic Group.
        .Parameter DynamicGroup
            Name (wildcards supported) or GUID of the Dynamic Group.
        .Parameter OrgUnit
            Valid GUID of a OrgUnit with Dynamic Groups
        .Outputs
            Array of DynamicGroup (see bConnect documentation for more details)
    #>


    Param(
        [string]$DynamicGroup,
        [string]$OrgUnit
    )

    $_connectVersion = Get-bConnectVersion
    If($_connectVersion -ge "1.0") {
        If(![string]::IsNullOrEmpty($DynamicGroup)) {
            If(Test-Guid $DynamicGroup) {
                $_body = @{
                    Id = $DynamicGroup
                }

                return Invoke-bConnectGet -Controller "DynamicGroups" -Data $_body -Version $_connectVersion
            } else {
                # fetching dynamic groups with name is not supported; therefore we need a workaround for getting the specified dyn group...
                $_bmsVersion = Get-bConnectInfo
                If($_bmsVersion.bMSVersion -imatch "16.*") {
                    # Search available since bMS 2016R1
                    $_groups = Search-bConnectDynamicGroup -Term $DynamicGroup
                    $_ret_groups = @()
                    Foreach($_grp in $_groups) {
                        $_ret_groups += Get-bConnectDynamicGroup -DynamicGroup $_grp.Id
                    }

                    return $_ret_groups
                }
                return $false
            }
        } elseif (![string]::IsNullOrEmpty($OrgUnit)) {
            If(Test-Guid $OrgUnit) {
                $_body = @{
                    OrgUnit = $OrgUnit
                }

                return Invoke-bConnectGet -Controller "DynamicGroups" -Data $_body -Version $_connectVersion
            } else {
                return $false
            }
        } else {
            return Invoke-bConnectGet -Controller "DynamicGroups" -Version $_connectVersion
        }
    } else {
        return $false
    }
}