Skip to content

Commit 269148d

Browse files
Merge pull request KelvinTegelaar#1497 from kris6673/fix-standards
Fix: Improve logging and fix report mode issues
2 parents 307866a + 97c8c01 commit 269148d

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,38 @@ function Invoke-CIPPStandardDisableAdditionalStorageProviders {
3333
param($Tenant, $Settings)
3434
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'DisableAdditionalStorageProviders'
3535

36-
$AdditionalStorageProvidersState = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OwaMailboxPolicy' -cmdParams @{Identity = 'OwaMailboxPolicy-Default' }
36+
$AdditionalStorageProvidersState = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OwaMailboxPolicy' -cmdParams @{Identity = 'OwaMailboxPolicy-Default' } -Select 'Identity, AdditionalStorageProvidersAvailable'
3737

3838
if ($Settings.remediate -eq $true) {
3939

4040
try {
4141
if ($AdditionalStorageProvidersState.AdditionalStorageProvidersAvailable) {
42-
New-ExoRequest -tenantid $Tenant -cmdlet 'Set-OwaMailboxPolicy' -cmdParams @{ Identity = $AdditionalStorageProvidersState.Identity; AdditionalStorageProvidersAvailable = $false } -useSystemMailbox $true
43-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'OWA additional storage providers have been disabled.' -sev Info
42+
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-OwaMailboxPolicy' -cmdParams @{ Identity = $AdditionalStorageProvidersState.Identity; AdditionalStorageProvidersAvailable = $false } -useSystemMailbox $true
43+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'OWA additional storage providers has been disabled.' -sev Info
4444
$AdditionalStorageProvidersState.AdditionalStorageProvidersAvailable = $false
4545
} else {
46-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'OWA additional storage providers are already disabled.' -sev Info
46+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'OWA additional storage providers are already disabled.' -sev Info
4747
}
4848
} catch {
49-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
50-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to disable OWA additional storage providers. Error: $ErrorMessage" -sev Error
49+
$ErrorMessage = Get-CippException -Exception $_
50+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to disable OWA additional storage providers. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
5151
}
5252

5353
}
5454

5555
if ($Settings.alert -eq $true) {
5656
if ($AdditionalStorageProvidersState.AdditionalStorageProvidersAvailable) {
5757
$Object = $AdditionalStorageProvidersState | Select-Object -Property AdditionalStorageProvidersAvailable
58-
Write-StandardsAlert -message 'OWA additional storage providers are enabled' -object $Object -tenant $tenant -standardName 'DisableAdditionalStorageProviders' -standardId $Settings.standardId
59-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'OWA additional storage providers are enabled' -sev Info
58+
Write-StandardsAlert -message 'OWA additional storage providers are enabled' -object $Object -tenant $Tenant -standardName 'DisableAdditionalStorageProviders' -standardId $Settings.standardId
59+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'OWA additional storage providers are enabled' -sev Info
6060
} else {
61-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'OWA additional storage providers are disabled' -sev Info
61+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'OWA additional storage providers are disabled' -sev Info
6262
}
6363
}
6464

6565
if ($Settings.report -eq $true) {
66-
$state = $AdditionalStorageProvidersState.AdditionalStorageProvidersEnabled ? $false : $true
67-
Set-CIPPStandardsCompareField -FieldName 'standards.DisableAdditionalStorageProviders' -FieldValue $state -TenantFilter $Tenant
68-
Add-CIPPBPAField -FieldName 'AdditionalStorageProvidersEnabled' -FieldValue $AdditionalStorageProvidersState.AdditionalStorageProvidersEnabled -StoreAs bool -Tenant $tenant
66+
$State = $AdditionalStorageProvidersState.AdditionalStorageProvidersEnabled ? $false : $true
67+
Set-CIPPStandardsCompareField -FieldName 'standards.DisableAdditionalStorageProviders' -FieldValue $State -TenantFilter $Tenant
68+
Add-CIPPBPAField -FieldName 'AdditionalStorageProvidersEnabled' -FieldValue $State -StoreAs bool -Tenant $Tenant
6969
}
7070
}

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

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,31 @@ function Invoke-CIPPStandardPWcompanionAppAllowedState {
3030

3131
param($Tenant, $Settings)
3232

33-
$authenticatorFeaturesState = (New-GraphGetRequest -tenantid $Tenant -Uri 'https://graph.microsoft.com/beta/policies/authenticationMethodsPolicy/authenticationMethodConfigurations/microsoftAuthenticator')
34-
$authState = if ($authenticatorFeaturesState.featureSettings.companionAppAllowedState.state -eq 'enabled') { $true } else { $false }
35-
36-
33+
$AuthenticatorFeaturesState = (New-GraphGetRequest -tenantid $Tenant -Uri 'https://graph.microsoft.com/beta/policies/authenticationMethodsPolicy/authenticationMethodConfigurations/microsoftAuthenticator')
3734

3835
# Get state value using null-coalescing operator
39-
$state = $Settings.state.value ? $Settings.state.value : $settings.state
40-
$authState = if ($authenticatorFeaturesState.featureSettings.companionAppAllowedState.state -eq $state) { $true } else { $false }
36+
$CurrentState = $AuthenticatorFeaturesState.featureSettings.companionAppAllowedState.state
37+
$WantedState = $Settings.state.value ? $Settings.state.value : $settings.state
38+
$AuthStateCorrect = if ($CurrentState -eq $WantedState) { $true } else { $false }
4139

4240
# Input validation
43-
if (([string]::IsNullOrWhiteSpace($state) -or $state -eq 'Select a value') -and ($Settings.remediate -eq $true -or $Settings.alert -eq $true)) {
41+
if (([string]::IsNullOrWhiteSpace($WantedState) -or $WantedState -eq 'Select a value') -and ($Settings.remediate -eq $true -or $Settings.alert -eq $true)) {
4442
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'PWcompanionAppAllowedState: Invalid state parameter set' -sev Error
4543
Return
4644
}
4745

4846
If ($Settings.remediate -eq $true) {
47+
Write-Host "Remediating PWcompanionAppAllowedState for tenant $Tenant to $WantedState"
4948

50-
if ($authenticatorFeaturesState.featureSettings.companionAppAllowedState.state -eq $state) {
51-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "companionAppAllowedState is already set to the desired state of $state." -sev Info
49+
if ($AuthStateCorrect -eq $true) {
50+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "companionAppAllowedState is already set to the desired state of $WantedState." -sev Info
5251
} else {
5352
try {
5453
# Remove number matching from featureSettings because this is now Microsoft enforced and shipping it returns an error
55-
$authenticatorFeaturesState.featureSettings.PSObject.Properties.Remove('numberMatchingRequiredState')
54+
$AuthenticatorFeaturesState.featureSettings.PSObject.Properties.Remove('numberMatchingRequiredState')
5655
# Define feature body
5756
$featureBody = @{
58-
state = $state
57+
state = $WantedState
5958
includeTarget = [PSCustomObject]@{
6059
targetType = 'group'
6160
id = 'all_users'
@@ -65,33 +64,33 @@ function Invoke-CIPPStandardPWcompanionAppAllowedState {
6564
id = '00000000-0000-0000-0000-000000000000'
6665
}
6766
}
68-
$authenticatorFeaturesState.featureSettings.companionAppAllowedState = $featureBody
69-
$body = ConvertTo-Json -Depth 3 -Compress -InputObject $authenticatorFeaturesState
67+
$AuthenticatorFeaturesState.featureSettings.companionAppAllowedState = $featureBody
68+
$body = ConvertTo-Json -Depth 3 -Compress -InputObject $AuthenticatorFeaturesState
7069
$null = (New-GraphPostRequest -tenantid $Tenant -Uri 'https://graph.microsoft.com/beta/policies/authenticationMethodsPolicy/authenticationMethodConfigurations/microsoftAuthenticator' -Type patch -Body $body -ContentType 'application/json')
71-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Set companionAppAllowedState to $state." -sev Info
70+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Set companionAppAllowedState to $WantedState." -sev Info
7271
} catch {
7372
$ErrorMessage = Get-CippExceptionMessage -Exception $_
74-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to set companionAppAllowedState to $state. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
73+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to set companionAppAllowedState to $WantedState. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
7574
}
7675
}
7776
}
7877

7978
if ($Settings.alert -eq $true) {
8079

81-
if ($authState) {
82-
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'companionAppAllowedState is enabled.' -sev Info
80+
if ($AuthStateCorrect -eq $true) {
81+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "companionAppAllowedState is set to $WantedState." -sev Info
8382
} else {
84-
Write-StandardsAlert -message 'companionAppAllowedState is not enabled' -object $authenticatorFeaturesState -tenant $Tenant -standardName 'PWcompanionAppAllowedState' -standardId $Settings.standardId
85-
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'companionAppAllowedState is not enabled.' -sev Info
83+
Write-StandardsAlert -message "companionAppAllowedState is not set to $WantedState. Current state is $CurrentState." -object $AuthenticatorFeaturesState -tenant $Tenant -standardName 'PWcompanionAppAllowedState' -standardId $Settings.standardId
84+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "companionAppAllowedState is not set to $WantedState. Current state is $CurrentState." -sev Info
8685
}
8786
}
8887

8988
if ($Settings.report -eq $true) {
90-
Add-CIPPBPAField -FieldName 'companionAppAllowedState' -FieldValue $authState -StoreAs bool -Tenant $Tenant
91-
if ($authState) {
89+
Add-CIPPBPAField -FieldName 'companionAppAllowedState' -FieldValue $AuthStateCorrect -StoreAs bool -Tenant $Tenant
90+
if ($AuthStateCorrect -eq $true) {
9291
$FieldValue = $true
9392
} else {
94-
$FieldValue = $authenticatorFeaturesState.featureSettings.companionAppAllowedState
93+
$FieldValue = $AuthenticatorFeaturesState.featureSettings.companionAppAllowedState
9594
}
9695
Set-CIPPStandardsCompareField -FieldName 'standards.PWcompanionAppAllowedState' -FieldValue $FieldValue -Tenant $Tenant
9796
}

0 commit comments

Comments
 (0)