@@ -16,8 +16,7 @@ function Invoke-EditGroup {
1616 $UserObj = $Request.Body
1717 $GroupType = $UserObj.groupId.addedFields.groupType ? $UserObj.groupId.addedFields.groupType : $UserObj.groupType
1818 $GroupName = $UserObj.groupName ? $UserObj.groupName : $UserObj.groupId.addedFields.groupName
19-
20- # Write-Warning ($Request.Body | ConvertTo-Json -Depth 10)
19+ $OrgGroup = New-GraphGetRequest - uri " https://graph.microsoft.com/beta/groups/$ ( $UserObj.groupId ) " - tenantid $UserObj.tenantFilter
2120
2221 $AddMembers = $UserObj.AddMember
2322 $UserObj.groupId = $UserObj.groupId.value ?? $UserObj.groupId
@@ -30,6 +29,39 @@ function Invoke-EditGroup {
3029 $ExoBulkRequests = [System.Collections.Generic.List [object ]]::new()
3130 $ExoLogs = [System.Collections.Generic.List [object ]]::new()
3231
32+ # Edit properties:
33+ if ($GroupType -eq ' Distribution List' -or $GroupType -eq ' Mail-Enabled Security' ) {
34+ $Params = @ { Identity = $UserObj.groupId ; DisplayName = $UserObj.displayName ; Description = $UserObj.description ; name = $UserObj.mailNickname }
35+ $ExoBulkRequests.Add (@ {
36+ CmdletInput = @ {
37+ CmdletName = ' Set-DistributionGroup'
38+ Parameters = $Params
39+ }
40+ })
41+ $ExoLogs.Add (@ {
42+ message = " Success - Edited group properties for $ ( $GroupName ) group. It might take some time to reflect the changes."
43+ target = $UserObj.groupId
44+ })
45+ } else {
46+ $PatchObj = @ {
47+ displayName = $UserObj.displayName
48+ description = $UserObj.description
49+ mailNickname = $UserObj.mailNickname
50+ mailEnabled = $OrgGroup.mailEnabled
51+ securityEnabled = $OrgGroup.securityEnabled
52+ }
53+ Write-Host " body: $ ( $PatchObj | ConvertTo-Json - Depth 10 - Compress) " - ForegroundColor Yellow
54+ if ($UserObj.membershipRules ) { $PatchObj | Add-Member - MemberType NoteProperty - Name ' membershipRule' - Value $UserObj.membershipRules - Force }
55+ try {
56+ $patch = New-GraphPOSTRequest - type PATCH - uri " https://graph.microsoft.com/beta/groups/$ ( $UserObj.groupId ) " - tenantid $UserObj.tenantFilter - body ($PatchObj | ConvertTo-Json - Depth 10 - Compress)
57+ $Results.Add (" Success - Edited group properties for $ ( $GroupName ) group. It might take some time to reflect the changes." )
58+ Write-LogMessage - headers $Headers - API $APIName - tenant $UserObj.tenantFilter - message " Edited group properties for $ ( $GroupName ) group" - Sev ' Info'
59+ } catch {
60+ $Results.Add (" Error - Failed to edit group properties: $ ( $_.Exception.Message ) " )
61+ Write-LogMessage - headers $Headers - API $APIName - tenant $UserObj.tenantFilter - message " Failed to patch group: $ ( $_.Exception.Message ) " - Sev ' Error'
62+ }
63+ }
64+
3365 if ($AddMembers ) {
3466 $AddMembers | ForEach-Object {
3567 try {
@@ -257,6 +289,8 @@ function Invoke-EditGroup {
257289 })
258290 }
259291
292+
293+
260294 Write-Information " Graph Bulk Requests: $ ( $BulkRequests.Count ) "
261295 if ($BulkRequests.Count -gt 0 ) {
262296 # Write-Warning 'EditUser - Executing Graph Bulk Requests'
0 commit comments