You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Contacts/Invoke-ListContacts.ps1
+40-32Lines changed: 40 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
usingnamespaceSystem.Collections.Generic
2
2
usingnamespaceSystem.Text.RegularExpressions
3
3
4
-
FunctionInvoke-ListContacts {
4
+
functionInvoke-ListContacts {
5
5
<#
6
6
.FUNCTIONALITY
7
7
Entrypoint
@@ -18,10 +18,9 @@ Function Invoke-ListContacts {
18
18
# Early validation and exit
19
19
if (-not$TenantFilter) {
20
20
return ([HttpResponseContext]@{
21
-
StatusCode= [HttpStatusCode]::BadRequest
22
-
Body='tenantFilter is required'
23
-
})
24
-
return
21
+
StatusCode= [HttpStatusCode]::BadRequest
22
+
Body='tenantFilter is required'
23
+
})
25
24
}
26
25
27
26
# Pre-compiled regex for MailTip cleaning
@@ -52,35 +51,35 @@ Function Invoke-ListContacts {
$Results.Add("Could not remove $Username from group '$GroupName' because it has assigned licenses. These groups are removed during the license removal step.")
43
+
Write-LogMessage-headers $Headers-API $APIName-message "Could not remove $Username from group '$GroupName' because it has assigned licenses. These groups are removed during the license removal step."-Sev 'Warning'-tenant $TenantFilter
44
+
} elseif ($IsDynamic) {
45
+
$Results.Add("Error: Could not remove $Username from group '$GroupName' because it is a Dynamic Group.")
46
+
Write-LogMessage-headers $Headers-API $APIName-message "Could not remove $Username from group '$GroupName' because it is a Dynamic Group."-Sev 'Warning'-tenant $TenantFilter
47
+
} elseif ($GroupInfo.onPremisesSyncEnabled) {
48
+
$Results.Add("Error: Could not remove $Username from group '$GroupName' because it is synced with Active Directory.")
49
+
Write-LogMessage-headers $Headers-API $APIName-message "Could not remove $Username from group '$GroupName' because it is synced with Active Directory."-Sev 'Warning'-tenant $TenantFilter
50
+
} else {
51
+
if ($IsM365Group-or (-not$IsMailEnabled)) {
52
+
# Use Graph API for M365 Groups and Security Groups
53
+
$BulkRequests.Add(@{
54
+
id="removeFromGroup-$Group"
55
+
method='DELETE'
56
+
url="groups/$Group/members/$UserID/`$ref"
57
+
})
58
+
$GraphLogs.Add(@{
59
+
message="Removed $Username from $GroupName"
60
+
id="removeFromGroup-$Group"
61
+
groupName=$GroupName
62
+
})
63
+
} elseif ($IsMailEnabled) {
64
+
# Use Exchange Online for Distribution Lists
65
+
$Params=@{
66
+
Identity=$GroupName
67
+
Member=$UserID
68
+
BypassSecurityGroupManagerCheck=$true
37
69
}
70
+
$ExoBulkRequests.Add(@{
71
+
CmdletInput=@{
72
+
CmdletName='Remove-DistributionGroupMember'
73
+
Parameters=$Params
74
+
}
75
+
})
76
+
$ExoLogs.Add(@{
77
+
message="Removed $Username from $GroupName"
78
+
target=$UserID
79
+
groupName=$GroupName
80
+
})
81
+
}
82
+
}
83
+
}
38
84
39
-
Write-LogMessage-headers $using:Headers-API $($using:APIName) -message "Removed $($using:Username) from $GroupName"-Sev 'Info'-tenant $using:TenantFilter
40
-
"Successfully removed $($using:Username) from group $GroupName"
$Results.Add("Could not remove $Username from group '$($GraphLog.groupName)': $Message. This is likely because it's a Dynamic Group or synced with Active Directory")
95
+
Write-LogMessage-headers $Headers-API $APIName-message "Could not remove $Username from group '$($GraphLog.groupName)': $Message"-Sev 'Error'-tenant $TenantFilter
96
+
} else {
97
+
$Results.Add("Successfully removed $Username from group '$($GraphLog.groupName)'")
Write-LogMessage-headers $using:Headers-API $($using:APIName)-message "Could not remove $($using:Username) from group $GroupName: $($ErrorMessage.NormalizedError)"-Sev 'Error'-tenant $using:TenantFilter-LogData $ErrorMessage
45
-
"Could not remove $($using:Username) from group $($GroupName): $($ErrorMessage.NormalizedError). This is likely because its a Dynamic Group or synched with active directory"
0 commit comments