Skip to content

Commit 6bd0491

Browse files
committed
fix: check if $state -eq $true
1 parent b713768 commit 6bd0491

12 files changed

Lines changed: 166 additions & 111 deletions

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,31 @@ function Invoke-CIPPStandardDisableEmail {
2929
param($Tenant, $Settings)
3030
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'DisableEmail'
3131

32-
$CurrentInfo = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/Email' -tenantid $Tenant
33-
$State = if ($CurrentInfo.state -eq 'enabled') { $true } else { $false }
32+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/Email' -tenantid $Tenant
33+
$StateIsCorrect = ($CurrentState.state -eq 'disabled')
3434

3535
If ($Settings.remediate -eq $true) {
36-
if ($State) {
37-
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'Email' -Enabled $false
38-
} else {
36+
if ($StateIsCorrect -eq $true) {
3937
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Email authentication method is already disabled.' -sev Info
38+
} else {
39+
try {
40+
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'Email' -Enabled $false
41+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Email authentication method disabled' -sev Info
42+
} catch {
43+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Failed to disable Email authentication method' -sev Error -LogData $_
44+
}
4045
}
4146
}
4247

4348
if ($Settings.alert -eq $true) {
44-
if ($State) {
49+
if ($StateIsCorrect -eq $true) {
4550
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Email authentication method is enabled' -sev Alert
4651
} else {
4752
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Email authentication method is not enabled' -sev Info
4853
}
4954
}
5055

5156
if ($Settings.report -eq $true) {
52-
Add-CIPPBPAField -FieldName 'DisableEmail' -FieldValue $State -StoreAs bool -Tenant $tenant
57+
Add-CIPPBPAField -FieldName 'DisableEmail' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5358
}
5459
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,31 @@ function Invoke-CIPPStandardDisableSMS {
2929
param($Tenant, $Settings)
3030
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'DisableSMS'
3131

32-
$CurrentInfo = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/SMS' -tenantid $Tenant
33-
$State = if ($CurrentInfo.state -eq 'enabled') { $true } else { $false }
32+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/SMS' -tenantid $Tenant
33+
$StateIsCorrect = ($CurrentState.state -eq 'disabled')
3434

3535
If ($Settings.remediate -eq $true) {
36-
if ($State) {
37-
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'SMS' -Enabled $false
38-
} else {
36+
if ($StateIsCorrect -eq $true) {
3937
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SMS authentication method is already disabled.' -sev Info
38+
} else {
39+
try {
40+
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'SMS' -Enabled $false
41+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SMS authentication method disabled' -sev Info
42+
} catch {
43+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Failed to disable SMS authentication method' -sev Error -LogData $_
44+
}
4045
}
4146
}
4247

4348
if ($Settings.alert -eq $true) {
44-
if ($State) {
49+
if ($StateIsCorrect -eq $true) {
4550
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SMS authentication method is enabled' -sev Alert
4651
} else {
4752
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SMS authentication method is not enabled' -sev Info
4853
}
4954
}
5055

5156
if ($Settings.report -eq $true) {
52-
Add-CIPPBPAField -FieldName 'DisableSMS' -FieldValue $State -StoreAs bool -Tenant $tenant
57+
Add-CIPPBPAField -FieldName 'DisableSMS' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5358
}
5459
}

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,39 @@ function Invoke-CIPPStandardDisableTenantCreation {
3131
param($Tenant, $Settings)
3232
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'DisableTenantCreation'
3333

34-
$CurrentInfo = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authorizationPolicy/authorizationPolicy' -tenantid $Tenant
35-
$State = $CurrentInfo.defaultUserRolePermissions.allowedToCreateTenants
34+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authorizationPolicy/authorizationPolicy' -tenantid $Tenant
35+
$StateIsCorrect = ($CurrentState.defaultUserRolePermissions.allowedToCreateTenants -eq $false)
3636

3737
If ($Settings.remediate -eq $true) {
38-
39-
if ($State) {
38+
if ($StateIsCorrect -eq $true) {
39+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Users are already disabled from creating tenants.' -sev Info
40+
} else {
4041
try {
41-
$body = '{"defaultUserRolePermissions":{"allowedToCreateTenants":false}}'
42-
New-GraphPostRequest -tenantid $tenant -Uri 'https://graph.microsoft.com/beta/policies/authorizationPolicy/authorizationPolicy' -Type patch -Body $body -ContentType 'application/json'
42+
$GraphRequest = @{
43+
tenantid = $tenant
44+
uri = 'https://graph.microsoft.com/beta/policies/authorizationPolicy/authorizationPolicy'
45+
AsApp = $false
46+
Type = 'PATCH'
47+
ContentType = 'application/json'
48+
Body = '{"defaultUserRolePermissions":{"allowedToCreateTenants":false}}'
49+
}
50+
New-GraphPostRequest @GraphRequest
4351
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Disabled users from creating tenants.' -sev Info
44-
$State = $false
4552
} catch {
46-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
47-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to disable users from creating tenants: $ErrorMessage" -sev 'Error'
53+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to disable users from creating tenants" -sev 'Error' -LogData $_
4854
}
49-
} else {
50-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Users are already disabled from creating tenants.' -sev Info
5155
}
5256
}
53-
if ($Settings.alert -eq $true) {
5457

55-
if ($State) {
56-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Users are allowed to create tenants.' -sev Alert
57-
} else {
58+
if ($Settings.alert -eq $true) {
59+
if ($StateIsCorrect -eq $true) {
5860
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Users are not allowed to create tenants.' -sev Info
61+
} else {
62+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Users are allowed to create tenants.' -sev Alert
5963
}
6064
}
65+
6166
if ($Settings.report -eq $true) {
62-
Add-CIPPBPAField -FieldName 'DisableTenantCreation' -FieldValue $State -StoreAs bool -Tenant $tenant
67+
Add-CIPPBPAField -FieldName 'DisableTenantCreation' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
6368
}
6469
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,31 @@ function Invoke-CIPPStandardDisableVoice {
2929
param($Tenant, $Settings)
3030
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'DisableVoice'
3131

32-
$CurrentInfo = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/Voice' -tenantid $Tenant
33-
$State = if ($CurrentInfo.state -eq 'enabled') { $true } else { $false }
32+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/Voice' -tenantid $Tenant
33+
$StateIsCorrect = ($CurrentState.state -eq 'disabled')
3434

3535
If ($Settings.remediate -eq $true) {
36-
if ($State) {
37-
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'Voice' -Enabled $false
38-
} else {
36+
if ($StateIsCorrect -eq $true) {
3937
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Voice authentication method is already disabled.' -sev Info
38+
} else {
39+
try {
40+
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'Voice' -Enabled $false
41+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Voice authentication method disabled' -sev Info
42+
} catch {
43+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Failed to disable Voice authentication method' -sev Error -LogData $_
44+
}
4045
}
4146
}
4247

4348
if ($Settings.alert -eq $true) {
44-
if ($State) {
49+
if ($StateIsCorrect -eq $true) {
4550
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Voice authentication method is enabled' -sev Alert
4651
} else {
4752
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Voice authentication method is not enabled' -sev Info
4853
}
4954
}
5055

5156
if ($Settings.report -eq $true) {
52-
Add-CIPPBPAField -FieldName 'DisableVoice' -FieldValue $State -StoreAs bool -Tenant $tenant
57+
Add-CIPPBPAField -FieldName 'DisableVoice' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5358
}
5459
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,32 @@ function Invoke-CIPPStandardDisablex509Certificate {
2929
param($Tenant, $Settings)
3030
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'Disablex509Certificate'
3131

32-
$CurrentInfo = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/x509Certificate' -tenantid $Tenant
33-
$State = if ($CurrentInfo.state -eq 'enabled') { $true } else { $false }
32+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/x509Certificate' -tenantid $Tenant
33+
$StateIsCorrect = ($CurrentState.state -eq 'disabled')
3434

3535
If ($Settings.remediate -eq $true) {
36-
if ($State) {
37-
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'x509Certificate' -Enabled $false
38-
} else {
36+
if ($StateIsCorrect -eq $true) {
3937
Write-LogMessage -API 'Standards' -tenant $tenant -message 'x509Certificate authentication method is already disabled.' -sev Info
38+
} else {
39+
try {
40+
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'x509Certificate' -Enabled $false
41+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'x509Certificate authentication method disabled' -sev Info
42+
} catch {
43+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Failed to disable x509Certificate authentication method' -sev Error -LogData $_
44+
}
4045
}
4146
}
4247

4348
if ($Settings.alert -eq $true) {
44-
if ($State) {
49+
if ($StateIsCorrect -eq $true) {
4550
Write-LogMessage -API 'Standards' -tenant $tenant -message 'x509Certificate authentication method is enabled' -sev Alert
4651
} else {
4752
Write-LogMessage -API 'Standards' -tenant $tenant -message 'x509Certificate authentication method is not enabled' -sev Info
4853
}
4954
}
5055

5156
if ($Settings.report -eq $true) {
52-
Add-CIPPBPAField -FieldName 'Disablex509Certificate' -FieldValue $State -StoreAs bool -Tenant $tenant
57+
Add-CIPPBPAField -FieldName 'Disablex509Certificate' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5358
}
5459

5560
}

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,31 @@ function Invoke-CIPPStandardEnableFIDO2 {
2929
param($Tenant, $Settings)
3030
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'EnableFIDO2'
3131

32-
$CurrentInfo = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/Fido2' -tenantid $Tenant
33-
$State = if ($CurrentInfo.state -eq 'enabled') { $true } else { $false }
32+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/Fido2' -tenantid $Tenant
33+
$StateIsCorrect = ($CurrentState.state -eq 'enabled')
3434

3535
If ($Settings.remediate -eq $true) {
36-
37-
if ($State) {
36+
if ($StateIsCorrect -eq $true) {
3837
Write-LogMessage -API 'Standards' -tenant $tenant -message 'FIDO2 Support is already enabled.' -sev Info
3938
} else {
40-
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'Fido2' -Enabled $true
39+
try {
40+
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'Fido2' -Enabled $true
41+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'FIDO2 Support enabled' -sev Info
42+
} catch {
43+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Failed to enable FIDO2 Support' -sev Error -LogData $_
44+
}
4145
}
4246
}
4347

44-
4548
if ($Settings.alert -eq $true) {
46-
47-
if ($State) {
49+
if ($StateIsCorrect -eq $true) {
4850
Write-LogMessage -API 'Standards' -tenant $tenant -message 'FIDO2 Support is enabled' -sev Info
4951
} else {
5052
Write-LogMessage -API 'Standards' -tenant $tenant -message 'FIDO2 Support is not enabled' -sev Alert
5153
}
5254
}
5355

5456
if ($Settings.report -eq $true) {
55-
Add-CIPPBPAField -FieldName 'EnableFIDO2' -FieldValue $State -StoreAs bool -Tenant $tenant
57+
Add-CIPPBPAField -FieldName 'EnableFIDO2' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5658
}
57-
5859
}

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,31 @@ function Invoke-CIPPStandardEnableHardwareOAuth {
2929
param($Tenant, $Settings)
3030
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'EnableHardwareOAuth'
3131

32-
$CurrentInfo = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/HardwareOath' -tenantid $Tenant
33-
$State = if ($CurrentInfo.state -eq 'enabled') { $true } else { $false }
32+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/authenticationmethodspolicy/authenticationMethodConfigurations/HardwareOath' -tenantid $Tenant
33+
$StateIsCorrect = ($CurrentState.state -eq 'enabled')
3434

3535
If ($Settings.remediate -eq $true) {
36-
37-
if ($State) {
36+
if ($StateIsCorrect -eq $true) {
3837
Write-LogMessage -API 'Standards' -tenant $tenant -message 'HardwareOAuth Support is already enabled.' -sev Info
3938
} else {
40-
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'HardwareOath' -Enabled $true
39+
try {
40+
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'HardwareOath' -Enabled $true
41+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'HardwareOAuth Support enabled' -sev Info
42+
} catch {
43+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Failed to enable HardwareOAuth Support' -sev Error -LogData $_
44+
}
4145
}
4246
}
4347

4448
if ($Settings.alert -eq $true) {
45-
46-
if ($State) {
49+
if ($StateIsCorrect -eq $true) {
4750
Write-LogMessage -API 'Standards' -tenant $tenant -message 'HardwareOAuth Support is enabled' -sev Info
4851
} else {
4952
Write-LogMessage -API 'Standards' -tenant $tenant -message 'HardwareOAuth Support is not enabled' -sev Alert
5053
}
5154
}
5255

5356
if ($Settings.report -eq $true) {
54-
Add-CIPPBPAField -FieldName 'EnableHardwareOAuth' -FieldValue $State -StoreAs bool -Tenant $tenant
57+
Add-CIPPBPAField -FieldName 'EnableHardwareOAuth' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5558
}
5659
}

0 commit comments

Comments
 (0)