Skip to content

Commit

Permalink
Merge branch 'KelvinTegelaar:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dsghi authored Jan 23, 2024
2 parents 8e352ce + 6d3e6ec commit 3f8e321
Show file tree
Hide file tree
Showing 15 changed files with 12,696 additions and 2,988 deletions.
5,084 changes: 4,146 additions & 938 deletions ConversionTable.csv

Large diffs are not rendered by default.

5,084 changes: 4,146 additions & 938 deletions Modules/CIPPCore/Public/ConversionTable.csv

Large diffs are not rendered by default.

Large diffs are not rendered by default.

31 changes: 30 additions & 1 deletion Modules/CIPPCore/Public/GraphHelper/Get-NormalizedError.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,42 @@ function Get-NormalizedError {
param (
[string]$message
)

#Check if the message is valid JSON.
try {
$JSONMsg = $message | ConvertFrom-Json
} catch {
}
#if the message is valid JSON, there can be multiple fields in which the error resides. These are:
# $message.error.Innererror.Message
# $message.error.Message
# $message.error.details.message
# $message.error.innererror.internalException.message

#We need to check if the message is in one of these fields, and if so, return it.
if ($JSONMsg.error.innererror.message) {
Write-Host 'innererror.message found'
$message = $JSONMsg.error.innererror.message
} elseif ($JSONMsg.error.message) {
Write-Host 'error.message found'
$message = $JSONMsg.error.message
} elseif ($JSONMsg.error.details.message) {
Write-Host 'error.details.message found'
$message = $JSONMsg.error.details.message
} elseif ($JSONMsg.error.innererror.internalException.message) {
Write-Host 'error.innererror.internalException.message found'
$message = $JSONMsg.error.innererror.internalException.message
}


#finally, put the message through the translator. If it's not in the list, just return the original message
switch -Wildcard ($message) {
'Request not applicable to target tenant.' { 'Required license not available for this tenant' }
"Neither tenant is B2C or tenant doesn't have premium license" { 'This feature requires a P1 license or higher' }
'Response status code does not indicate success: 400 (Bad Request).' { 'Error 400 occured. There is an issue with the token configuration for this tenant. Please perform an access check' }
'*Microsoft.Skype.Sync.Pstn.Tnm.Common.Http.HttpResponseException*' { 'Could not connect to Teams Admin center - Tenant might be missing a Teams license' }
'*Provide valid credential.*' { 'Error 400: There is an issue with your Exchange Token configuration. Please perform an access check for this tenant' }
'*This indicate that a subscription within the tenant has lapsed*' { 'There is no exchange subscription available, or it has lapsed. Check licensing information.' }
'*This indicate that a subscription within the tenant has lapsed*' { 'There is subscription for this service available, Check licensing information.' }
'*User was not found.*' { 'The relationship between this tenant and the partner has been dissolved from the tenant side.' }
'*The user or administrator has not consented to use the application*' { 'CIPP cannot access this tenant. Perform a CPV Refresh and Access Check via the settings menu' }
'*AADSTS50020*' { 'AADSTS50020: The user you have used for your Secure Application Model is a guest in this tenant, or your are using GDAP and have not added the user to the correct group. Please delete the guest user to gain access to this tenant' }
Expand Down
13 changes: 4 additions & 9 deletions Modules/CIPPCore/Public/GraphHelper/New-GraphPOSTRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@ function New-GraphPOSTRequest ($uri, $tenantid, $body, $type, $scope, $AsApp, $N
try {
$ReturnedData = (Invoke-RestMethod -Uri $($uri) -Method $TYPE -Body $body -Headers $headers -ContentType $contentType)
} catch {
$Message = ($_.ErrorDetails.Message | ConvertFrom-Json -ErrorAction SilentlyContinue).error
if ($Message.innerError) { $Message = $Message.Innererror.Message } else { $Message = $Message.Message.Error }
if ($Message -eq $null) {
try {
$Message = ($_.ErrorDetails.Message | ConvertFrom-Json -ErrorAction SilentlyContinue).message
} catch {
$Message = $($_.Exception.Message)
}
$Message = if ($_.ErrorDetails.Message) {
Get-NormalizedError -Message $_.ErrorDetails.Message
} else {
$_.Exception.message
}
throw $Message
}
return $ReturnedData
} else {
Write-Error 'Not allowed. You cannot manage your own tenant or tenants not under your scope'

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,49 @@ function Invoke-CIPPStandardEnableOnlineArchiving {
Internal
#>
param($Tenant, $Settings)
$MailboxesNoArchive = (New-ExoRequest -tenantid $tenant -cmdlet 'get-mailbox' -cmdparams @{ Filter = 'ArchiveGuid -Eq "00000000-0000-0000-0000-000000000000" -AND RecipientTypeDetails -Eq "UserMailbox"' })

$MailboxPlans = @( 'ExchangeOnline', 'ExchangeOnlineEnterprise' )
$MailboxesNoArchive = $MailboxPlans | ForEach-Object {
New-ExoRequest -tenantid $Tenant -cmdlet 'Get-Mailbox' -cmdparams @{ MailboxPlan = $_; Filter = 'ArchiveGuid -Eq "00000000-0000-0000-0000-000000000000" -AND RecipientTypeDetails -Eq "UserMailbox"' }
Write-Host "Getting mailboxes without Online Archiving for plan $_"
}

If ($Settings.remediate) {


try {
$MailboxesNoArchive | ForEach-Object {
(New-ExoRequest -tenantid $tenant -cmdlet 'enable-Mailbox' -cmdparams @{ Identity = $_.UserPrincipalName; Archive = $true })
if ($null -eq $MailboxesNoArchive) {
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Online Archiving already enabled for all accounts' -sev Info
} else {
try {
$SuccessCounter = 0
$MailboxesNoArchive | ForEach-Object {
try {
New-ExoRequest -tenantid $Tenant -cmdlet 'Enable-Mailbox' -cmdparams @{ Identity = $_.UserPrincipalName; Archive = $true } | Out-Null
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Enabled Online Archiving for $($_.UserPrincipalName)" -sev Info
$SuccessCounter++
} catch {
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to Enable Online Archiving for $($_.UserPrincipalName). Error: $($_.exception.message)" -sev Error
}
}
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Enabled Online Archiving for $SuccessCounter accounts" -sev Info

} catch {
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to Enable Online Archiving for all accounts. Error: $($_.exception.message)" -sev Error
}
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Enabled Online Archiving for all accounts' -sev Info

} catch {
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to Enable Online Archiving for all accounts Error: $($_.exception.message)" -sev Error
}

}

if ($Settings.alert) {

if ($MailboxesNoArchive) {
Write-LogMessage -API 'Standards' -tenant $tenant -message "Mailboxes without Online Archiving: $($MailboxesNoArchive.count)" -sev Alert
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Mailboxes without Online Archiving: $($MailboxesNoArchive.Count)" -sev Alert
} else {
Write-LogMessage -API 'Standards' -tenant $tenant -message 'All mailboxes have Online Archiving enabled' -sev Info
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'All mailboxes have Online Archiving enabled' -sev Info
}
}

if ($Settings.report) {
$filtered = $MailboxesNoArchive | Select-Object -Property UserPrincipalName, Archive
Add-CIPPBPAField -FieldName 'EnableOnlineArchiving' -FieldValue $MailboxesNoArchive -StoreAs json -Tenant $tenant
$filtered = $MailboxesNoArchive | Select-Object -Property UserPrincipalName, ArchiveGuid
Add-CIPPBPAField -FieldName 'EnableOnlineArchiving' -FieldValue $filtered -StoreAs json -Tenant $Tenant
}
}
Loading

0 comments on commit 3f8e321

Please sign in to comment.