Skip to content

Commit a0e7e67

Browse files
authored
Merge pull request #504 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents c73f41d + 36d5c46 commit a0e7e67

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

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

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,53 +29,47 @@ function Invoke-CIPPStandardintuneRequireMFA {
2929
#>
3030

3131
param($Tenant, $Settings)
32-
$TestResult = Test-CIPPStandardLicense -StandardName 'intuneRequireMFA' -TenantFilter $Tenant -RequiredCapabilities @('INTUNE_A', 'MDM_Services', 'EMS', 'SCCM', 'MICROSOFTINTUNEPLAN1')
3332
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'intuneRequireMFA'
3433

35-
if ($TestResult -eq $false) {
36-
Write-Host "We're exiting as the correct license is not present for this standard."
37-
return $true
38-
} #we're done.
39-
4034
try {
4135
$PreviousSetting = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/policies/deviceRegistrationPolicy' -tenantid $Tenant
42-
}
43-
catch {
44-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
45-
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the intuneRequireMFA state for $Tenant. Error: $ErrorMessage" -Sev Error
36+
} catch {
37+
$ErrorMessage = Get-CippException -Exception $_
38+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the intuneRequireMFA state for $Tenant. Error: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage
4639
return
4740
}
4841

49-
If ($Settings.remediate -eq $true) {
42+
if ($Settings.remediate -eq $true) {
5043
if ($PreviousSetting.multiFactorAuthConfiguration -eq 'required') {
51-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Require to use MFA when joining/registering Entra Devices is already enabled.' -sev Info
44+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Require to use MFA when joining/registering Entra Devices is already enabled.' -sev Info
5245
} else {
5346
try {
5447
$NewSetting = $PreviousSetting
5548
$NewSetting.multiFactorAuthConfiguration = 'required'
5649
$NewBody = ConvertTo-Json -Compress -InputObject $NewSetting -Depth 10
57-
New-GraphPostRequest -tenantid $tenant -Uri 'https://graph.microsoft.com/beta/policies/deviceRegistrationPolicy' -Type PUT -Body $NewBody -ContentType 'application/json'
58-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Set required to use MFA when joining/registering Entra Devices' -sev Info
50+
New-GraphPostRequest -tenantid $Tenant -Uri 'https://graph.microsoft.com/beta/policies/deviceRegistrationPolicy' -Type PUT -Body $NewBody
51+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Set required to use MFA when joining/registering Entra Devices' -sev Info
52+
$PreviousSetting.multiFactorAuthConfiguration = 'required'
5953
} catch {
60-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
61-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to set require to use MFA when joining/registering Entra Devices: $ErrorMessage" -sev Error
54+
$ErrorMessage = Get-CippException -Exception $_
55+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to set require to use MFA when joining/registering Entra Devices: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
6256
}
6357
}
6458
}
6559

6660
if ($Settings.alert -eq $true) {
6761

6862
if ($PreviousSetting.multiFactorAuthConfiguration -eq 'required') {
69-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Require to use MFA when joining/registering Entra Devices is enabled.' -sev Info
63+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Require to use MFA when joining/registering Entra Devices is enabled.' -sev Info
7064
} else {
71-
Write-StandardsAlert -message 'Require to use MFA when joining/registering Entra Devices is not enabled' -object $PreviousSetting -tenant $tenant -standardName 'intuneRequireMFA' -standardId $Settings.standardId
72-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Require to use MFA when joining/registering Entra Devices is not enabled.' -sev Info
65+
Write-StandardsAlert -message 'Require to use MFA when joining/registering Entra Devices is not enabled' -object $PreviousSetting -tenant $Tenant -standardName 'intuneRequireMFA' -standardId $Settings.standardId
66+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Require to use MFA when joining/registering Entra Devices is not enabled.' -sev Info
7367
}
7468
}
7569

7670
if ($Settings.report -eq $true) {
7771
$RequireMFA = if ($PreviousSetting.multiFactorAuthConfiguration -eq 'required') { $true } else { $false }
78-
Set-CIPPStandardsCompareField -FieldName 'standards.intuneRequireMFA' -FieldValue $RequireMFA -Tenant $tenant
79-
Add-CIPPBPAField -FieldName 'intuneRequireMFA' -FieldValue $RequireMFA -StoreAs bool -Tenant $tenant
72+
Set-CIPPStandardsCompareField -FieldName 'standards.intuneRequireMFA' -FieldValue $RequireMFA -Tenant $Tenant
73+
Add-CIPPBPAField -FieldName 'intuneRequireMFA' -FieldValue $RequireMFA -StoreAs bool -Tenant $Tenant
8074
}
8175
}

0 commit comments

Comments
 (0)