forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request KelvinTegelaar#859 from kris6673/cloudrecall
Add cloud message recall standard
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardCloudMessageRecall.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
function Invoke-CIPPStandardCloudMessageRecall { | ||
<# | ||
.FUNCTIONALITY | ||
Internal | ||
#> | ||
param($Tenant, $Settings) | ||
|
||
# Input validation | ||
if ([string]::isNullOrEmpty($Settings.state) -or $Settings.state -eq 'Select a value') { | ||
Write-LogMessage -API 'Standards' -tenant $tenant -message 'MessageRecallEnabled: Invalid state parameter set' -sev Error | ||
Exit | ||
} | ||
|
||
$CurrentState = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OrganizationConfig').MessageRecallEnabled | ||
$WantedState = if ($Settings.state -eq 'true') { $true } else { $false } | ||
$StateIsCorrect = if ($CurrentState -eq $WantedState) { $true } else { $false } | ||
|
||
if ($Settings.remediate -eq $true) { | ||
Write-Host 'Time to remediate' | ||
if ($StateIsCorrect -eq $false) { | ||
try { | ||
New-ExoRequest -tenantid $Tenant -cmdlet 'Set-OrganizationConfig' -cmdParams @{ MessageRecallEnabled = $WantedState } -useSystemMailbox $true | ||
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully set the tenant Message Recall state to $($Settings.state)" -sev Info | ||
} catch { | ||
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message | ||
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to set the tenant Message Recall state to $($Settings.state). Error: $ErrorMessage" -sev Error | ||
} | ||
} else { | ||
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant Message Recall state is already set correctly to $($Settings.state)" -sev Info | ||
} | ||
|
||
} | ||
|
||
if ($Settings.alert -eq $true) { | ||
if ($StateIsCorrect -eq $true) { | ||
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant Message Recall is set correctly to $($Settings.state)" -sev Info | ||
} else { | ||
Write-LogMessage -API 'Standards' -tenant $tenant -message "The tenant Message Recall is not set correctly to $($Settings.state)" -sev Alert | ||
} | ||
} | ||
|
||
if ($Settings.report -eq $true) { | ||
# Default is not set, not set means it's enabled | ||
if ($null -eq $CurrentState ) { $CurrentState = $true } | ||
Add-CIPPBPAField -FieldName 'MessageRecall' -FieldValue $CurrentState -StoreAs bool -Tenant $tenant | ||
} | ||
|
||
} |