Functions/Groups/Set-GraphGroup.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
Function Set-GraphGroup
{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $true,
        ValueFromPipeline = $true,
        ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$GroupId,

        [Parameter()]
        [string]$DisplayName,

        [Parameter()]
        [string]$Description,

        [Parameter()]
        [bool]$MailEnabled,

        [Parameter()]
        [bool]$AutoSubscribeNewMembers, 

        [Parameter()]
        [string]$MailNickname,

        [Parameter()]
        [bool]$SecurityEnabled, 

        [Parameter()]
        [string[]]$GroupTypes,

        [Parameter()]
        [ValidateSet("Private","Public")]
        [string]$Visibility
    )

    $bodyRaw = @{ }
    if ($PSBoundParameters.ContainsKey('DisplayName'))
        { $bodyRaw["DisplayName"] = $DisplayName }
    if ($PSBoundParameters.ContainsKey('Description'))
        { $bodyRaw["Description"] = $Description }
    if ($PSBoundParameters.ContainsKey('MailEnabled'))
        { $bodyRaw["MailEnabled"] = $MailEnabled }
    if ($PSBoundParameters.ContainsKey('AutoSubscribeNewMembers'))
        { $bodyRaw["AutoSubscribeNewMembers"] = $AutoSubscribeNewMembers }
    if ($PSBoundParameters.ContainsKey('MailNickname'))
        { $bodyRaw["MailNickname"] = $MailNickname }
    if ($PSBoundParameters.ContainsKey('SecurityEnabled'))
        { $bodyRaw["SecurityEnabled"] = $SecurityEnabled }
    if ($PSBoundParameters.ContainsKey('GroupTypes'))
        { $bodyRaw["GroupTypes"] = $GroupTypes }
    if ($PSBoundParameters.ContainsKey('Visibility'))
        { $bodyRaw["Visibility"] = $Visibility }

    $body = $bodyRaw | ConvertTo-Json

    $uri = $global:PowerGraph_BaseUrl + "groups/$GroupId"

    Write-Verbose "Updating group $GroupId with $body"

    Invoke-MSGraphRequest -Uri $uri -Method Patch -Body $body
    
    return $group
}