@@ -15,34 +15,34 @@ Function Invoke-ListGroups {
15
15
Write-LogMessage - headers $Headers - API $APIName - message ' Accessed this API' - Sev ' Debug'
16
16
17
17
$TenantFilter = $Request.Query.TenantFilter
18
- $selectstring = " id,createdDateTime,displayName,description,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule,grouptypes ,onPremisesSyncEnabled,resourceProvisioningOptions,userPrincipalName&` $ expand=members(` $ select=userPrincipalName)"
18
+ $SelectString = ' id,createdDateTime,displayName,description,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule,groupTypes ,onPremisesSyncEnabled,resourceProvisioningOptions,userPrincipalName&$expand=members($select=userPrincipalName)'
19
19
20
20
$BulkRequestArrayList = [System.Collections.Generic.List [object ]]::new()
21
21
22
22
if ($Request.Query.GroupID ) {
23
- $selectstring = ' id,createdDateTime,displayName,description,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule,groupTypes,userPrincipalName'
23
+ $SelectString = ' id,createdDateTime,displayName,description,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule,groupTypes,userPrincipalName'
24
24
$BulkRequestArrayList.add (@ {
25
25
id = 1
26
26
method = ' GET'
27
- url = " groups/$ ( $Request.Query.GroupID ) ?`$ select=$selectstring "
27
+ url = " groups/$ ( $Request.Query.GroupID ) ?`$ select=$SelectString "
28
28
})
29
29
}
30
30
if ($Request.Query.members ) {
31
- $selectstring = ' id,userPrincipalName,displayName,hideFromOutlookClients,hideFromAddressLists,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule'
31
+ $SelectString = ' id,userPrincipalName,displayName,hideFromOutlookClients,hideFromAddressLists,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule'
32
32
$BulkRequestArrayList.add (@ {
33
33
id = 2
34
34
method = ' GET'
35
- url = " groups/$ ( $Request.Query.GroupID ) /members?`$ top=999&select=$selectstring "
35
+ url = " groups/$ ( $Request.Query.GroupID ) /members?`$ top=999&select=$SelectString "
36
36
})
37
37
}
38
38
39
39
if ($Request.Query.owners ) {
40
40
if ($Request.Query.groupType -ne ' Distribution List' -and $Request.Query.groupType -ne ' Mail-Enabled Security' ) {
41
- $selectstring = ' id,userPrincipalName,displayName,hideFromOutlookClients,hideFromAddressLists,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule'
41
+ $SelectString = ' id,userPrincipalName,displayName,hideFromOutlookClients,hideFromAddressLists,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule'
42
42
$BulkRequestArrayList.add (@ {
43
43
id = 3
44
44
method = ' GET'
45
- url = " groups/$ ( $Request.Query.GroupID ) /owners?`$ top=999&select=$selectstring "
45
+ url = " groups/$ ( $Request.Query.GroupID ) /owners?`$ top=999&select=$SelectString "
46
46
})
47
47
} else {
48
48
$OwnerIds = New-ExoRequest - cmdlet ' Get-DistributionGroup' - tenantid $TenantFilter - cmdParams @ {Identity = $Request.Query.GroupID } - useSystemMailbox $true | Select-Object - ExpandProperty ManagedBy
@@ -86,40 +86,32 @@ Function Invoke-ListGroups {
86
86
if ($BulkRequestArrayList.Count -gt 0 ) {
87
87
$RawGraphRequest = New-GraphBulkRequest - tenantid $TenantFilter - scope ' https://graph.microsoft.com/.default' - Requests @ ($BulkRequestArrayList ) - asapp $true
88
88
$GraphRequest = [PSCustomObject ]@ {
89
- groupInfo = ($RawGraphRequest | Where-Object { $_.id -eq 1 }).body
89
+ groupInfo = ($RawGraphRequest | Where-Object { $_.id -eq 1 }).body | Select-Object * , @ { Name = ' primDomain' ; Expression = { $_.mail -split ' @' | Select-Object - Last 1 } },
90
+ @ {Name = ' teamsEnabled' ; Expression = { if ($_.resourceProvisioningOptions -Like ' *Team*' ) { $true } else { $false } } },
91
+ @ {Name = ' calculatedGroupType' ; Expression = {
92
+ if ($_.mailEnabled -and $_.securityEnabled ) { ' Mail-Enabled Security' }
93
+ if (! $_.mailEnabled -and $_.securityEnabled ) { ' Security' }
94
+ if ($_.groupTypes -contains ' Unified' ) { ' Microsoft 365' }
95
+ if (([string ]::isNullOrEmpty($_.groupTypes )) -and ($_.mailEnabled ) -and (! $_.securityEnabled )) { ' Distribution List' }
96
+ }
97
+ }, @ {Name = ' dynamicGroupBool' ; Expression = { if ($_.groupTypes -contains ' DynamicMembership' ) { $true } else { $false } } }
90
98
members = ($RawGraphRequest | Where-Object { $_.id -eq 2 }).body.value
91
99
owners = ($RawGraphRequest | Where-Object { $_.id -eq 3 }).body.value
92
100
allowExternal = (! $OnlyAllowInternal )
93
101
sendCopies = $SendCopies
94
102
}
95
103
} else {
96
- $GraphRequest = New-GraphGetRequest - uri " https://graph.microsoft.com/beta/groups/$ ( $GroupID ) /$ ( $members ) ?`$ top=999&select=$selectstring " - tenantid $TenantFilter | Select-Object * , @ { Name = ' primDomain' ; Expression = { $_.mail -split ' @' | Select-Object - Last 1 } },
104
+ $GraphRequest = New-GraphGetRequest - uri " https://graph.microsoft.com/beta/groups/$ ( $GroupID ) /$ ( $members ) ?`$ top=999&select=$SelectString " - tenantid $TenantFilter | Select-Object * , @ { Name = ' primDomain' ; Expression = { $_.mail -split ' @' | Select-Object - Last 1 } },
97
105
@ {Name = ' membersCsv' ; Expression = { $_.members.userPrincipalName -join ' ,' } },
98
106
@ {Name = ' teamsEnabled' ; Expression = { if ($_.resourceProvisioningOptions -Like ' *Team*' ) { $true }else { $false } } },
99
107
@ {Name = ' calculatedGroupType' ; Expression = {
100
-
101
- if ($_.mailEnabled -and $_.securityEnabled ) {
102
- ' Mail-Enabled Security'
103
- }
104
- if (! $_.mailEnabled -and $_.securityEnabled ) {
105
- ' Security'
106
- }
107
- if ($_.groupTypes -contains ' Unified' ) {
108
- ' Microsoft 365'
109
- }
110
- if (([string ]::isNullOrEmpty($_.groupTypes )) -and ($_.mailEnabled ) -and (! $_.securityEnabled )) {
111
- ' Distribution List'
112
- }
108
+ if ($_.mailEnabled -and $_.securityEnabled ) { ' Mail-Enabled Security' }
109
+ if (! $_.mailEnabled -and $_.securityEnabled ) { ' Security' }
110
+ if ($_.groupTypes -contains ' Unified' ) { ' Microsoft 365' }
111
+ if (([string ]::isNullOrEmpty($_.groupTypes )) -and ($_.mailEnabled ) -and (! $_.securityEnabled )) { ' Distribution List' }
113
112
}
114
113
},
115
- @ {Name = ' dynamicGroupBool' ; Expression = {
116
- if ($_.groupTypes -contains ' DynamicMembership' ) {
117
- $true
118
- } else {
119
- $false
120
- }
121
- }
122
- }
114
+ @ {Name = ' dynamicGroupBool' ; Expression = { if ($_.groupTypes -contains ' DynamicMembership' ) { $true } else { $false } } }
123
115
$GraphRequest = @ ($GraphRequest | Sort-Object displayName)
124
116
}
125
117
0 commit comments