Skip to content

Commit c8a72f6

Browse files
authored
Merge pull request #139 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents a6dfc9d + 4176d85 commit c8a72f6

File tree

3 files changed

+53
-19
lines changed

3 files changed

+53
-19
lines changed

Modules/CIPPCore/Public/GraphHelper/Get-CippException.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
function Get-CippException {
22
Param(
3+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
34
$Exception
45
)
56

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAuditLog.ps1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,38 +43,38 @@ function Invoke-CIPPStandardAuditLog {
4343
$DehydratedTenant = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OrganizationConfig' -Select IsDehydrated).IsDehydrated
4444
if ($DehydratedTenant -eq $true) {
4545
try {
46-
New-ExoRequest -tenantid $Tenant -cmdlet 'Enable-OrganizationCustomization'
47-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Organization customization enabled.' -sev Info
46+
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Enable-OrganizationCustomization'
47+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Organization customization enabled.' -sev Info
4848
} catch {
49-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
50-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to enable organization customization. Error: $ErrorMessage" -sev Debug
49+
$ErrorMessage = Get-CippException -Exception $_
50+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to enable organization customization. Error: $($ErrorMessage.NormalizedError)" -sev Debug -LogData $ErrorMessage
5151
}
5252
}
5353

5454
try {
5555
if ($AuditLogEnabled -eq $true) {
56-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Unified Audit Log already enabled.' -sev Info
56+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Unified Audit Log already enabled.' -sev Info
5757
} else {
58-
New-ExoRequest -tenantid $Tenant -cmdlet 'Set-AdminAuditLogConfig' -cmdParams @{UnifiedAuditLogIngestionEnabled = $true }
59-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Unified Audit Log Enabled.' -sev Info
58+
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-AdminAuditLogConfig' -cmdParams @{UnifiedAuditLogIngestionEnabled = $true }
59+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Unified Audit Log Enabled.' -sev Info
6060
}
6161

6262
} catch {
63-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
64-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to apply Unified Audit Log. Error: $ErrorMessage" -sev Error
63+
$ErrorMessage = Get-CippException -Exception $_
64+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to apply Unified Audit Log. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
6565
}
6666
}
6767
if ($Settings.alert -eq $true) {
6868

6969
if ($AuditLogEnabled -eq $true) {
70-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Unified Audit Log is enabled' -sev Info
70+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Unified Audit Log is enabled' -sev Info
7171
} else {
72-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Unified Audit Log is not enabled' -sev Alert
72+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Unified Audit Log is not enabled' -sev Alert
7373
}
7474
}
7575

7676
if ($Settings.report -eq $true) {
7777

78-
Add-CIPPBPAField -FieldName 'AuditLog' -FieldValue $AuditLogEnabled -StoreAs bool -Tenant $tenant
78+
Add-CIPPBPAField -FieldName 'AuditLog' -FieldValue $AuditLogEnabled -StoreAs bool -Tenant $Tenant
7979
}
8080
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardSpoofWarn.ps1

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ function Invoke-CIPPStandardSpoofWarn {
4242

4343
# Get state value using null-coalescing operator
4444
$state = $Settings.state.value ?? $Settings.state
45+
$AllowListAdd = $Settings.AllowListAdd.value ?? $Settings.AllowListAdd
46+
47+
# Test if all entries in the AllowListAdd variable are in the AllowList
48+
$AllowListCorrect = $true
49+
$AllowListAddEntries = foreach ($entry in $AllowListAdd) {
50+
if ($CurrentInfo.AllowList -notcontains $entry) {
51+
$AllowListCorrect = $false
52+
Write-Host "AllowList entry $entry not found in current AllowList"
53+
$entry
54+
} else {
55+
Write-Host "AllowList entry $entry found in current AllowList."
56+
}
57+
}
58+
$AllowListAdd = @{'@odata.type' = '#Exchange.GenericHashTable'; Add = $AllowListAddEntries }
59+
60+
# Debug output
61+
# Write-Host ($CurrentInfo | ConvertTo-Json -Depth 10)
62+
# Write-Host ($AllowListAdd | ConvertTo-Json -Depth 10)
4563

4664
# Input validation
4765
if (([string]::IsNullOrWhiteSpace($state) -or $state -eq 'Select a value') -and ($Settings.remediate -eq $true -or $Settings.alert -eq $true)) {
@@ -50,22 +68,37 @@ function Invoke-CIPPStandardSpoofWarn {
5068
}
5169

5270
If ($Settings.remediate -eq $true) {
71+
Write-Host 'Time to remediate!'
5372
$status = if ($Settings.enable -and $Settings.disable) {
5473
# Handle pre standards v2.0 legacy settings when this was 2 separate standards
5574
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'You cannot both enable and disable the Spoof Warnings setting' -sev Error
5675
Return
5776
} elseif ($state -eq 'enabled' -or $Settings.enable) { $true } else { $false }
5877

59-
if ($CurrentInfo.Enabled -eq $status) {
60-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Outlook external spoof warnings are already set to $status." -sev Info
61-
} else {
62-
try {
78+
try {
79+
if ($CurrentInfo.Enabled -eq $status -and $AllowListCorrect -eq $true) {
80+
# Status correct, AllowList correct
81+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Outlook external spoof warnings are already set to $status and the AllowList is correct." -sev Info
82+
83+
} elseif ($CurrentInfo.Enabled -eq $status -and $AllowListCorrect -eq $false) {
84+
# Status correct, AllowList incorrect
85+
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-ExternalInOutlook' -cmdParams @{ AllowList = $AllowListAdd; }
86+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Outlook external spoof warnings already set to $status. Added $($AllowListAdd.Add -join ', ') to the AllowList." -sev Info
87+
88+
} elseif ($CurrentInfo.Enabled -ne $status -and $AllowListCorrect -eq $false) {
89+
# Status incorrect, AllowList incorrect
90+
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-ExternalInOutlook' -cmdParams @{ Enabled = $status; AllowList = $AllowListAdd; }
91+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Outlook external spoof warnings set to $status. Added $($AllowListAdd.Add -join ', ') to the AllowList." -sev Info
92+
93+
} else {
94+
# Status incorrect, AllowList correct
6395
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-ExternalInOutlook' -cmdParams @{ Enabled = $status; }
6496
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Outlook external spoof warnings set to $status." -sev Info
65-
} catch {
66-
$ErrorMessage = Get-CippException -Exception $_
67-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set Outlook external spoof warnings to $status. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
97+
6898
}
99+
} catch {
100+
$ErrorMessage = Get-CippException -Exception $_
101+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Could not set Outlook external spoof warnings to $status. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
69102
}
70103
}
71104

0 commit comments

Comments
 (0)