Skip to content

Commit a013600

Browse files
committed
Merge branch 'dev' of https://github.com/KelvinTegelaar/CIPP-API into dev
2 parents ffab43e + eddef92 commit a013600

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

Modules/CIPPCore/Public/Set-CIPPSAMAdminRoles.ps1

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,22 @@ function Set-CIPPSAMAdminRoles {
8383
$ActionLogs.Add('Added Service Principal to Compliance Center')
8484
} catch {
8585
$SpError = $_.Exception.Message
86-
if ($SpError -match 'already exist') {
87-
$ActionLogs.Add('Service Principal already added to Compliance Center')
88-
} else {
89-
$ActionLogs.Add("Failed to add Service Principal to Compliance Center: $SpError")
90-
$HasFailures = $true
86+
switch ($SpError) {
87+
{ $_ -match 'already exist' } { $ActionLogs.Add('Service Principal already added to Compliance Center') }
88+
{ $_ -match 'New-ServicePrincipal is not present' } { $ActionLogs.Add('Tenant does not have a license to use Compliance Center features. Skipping.') }
89+
default { $ActionLogs.Add("Failed to add Service Principal to Compliance Center: $SpError"); $HasFailures = $true }
9190
}
91+
9292
}
9393
try {
9494
$null = New-ExoRequest -cmdlet 'New-ServicePrincipal' -cmdParams @{AppId = $env:ApplicationID; ObjectId = $id; DisplayName = 'CIPP-SAM' } -tenantid $TenantFilter -useSystemMailbox $true -AsApp
9595
$ActionLogs.Add('Added Service Principal to Exchange Online')
9696
} catch {
9797
$SpError = $_.Exception.Message
98-
if ($SpError -match 'already exist') {
99-
$ActionLogs.Add('Service Principal already added to Exchange Online')
100-
} else {
101-
$ActionLogs.Add("Failed to add Service Principal to Exchange Online: $SpError")
102-
$HasFailures = $true
98+
switch ($SpError) {
99+
{ $_ -match 'already exist' } { $ActionLogs.Add('Service Principal already added to Compliance Center') }
100+
{ $_ -match 'Response status code does not indicate success' } { $ActionLogs.Add('Could not connect to Exchange, we received an access denied. This is expected if you do not have an exchange license.'); $HasFailures = $true }
101+
default { $ActionLogs.Add("Failed to add Service Principal to Compliance Center: $SpError"); $HasFailures = $true }
103102
}
104103
}
105104

0 commit comments

Comments
 (0)