Skip to content

Commit 8fc6150

Browse files
authored
Merge pull request KelvinTegelaar#1174 from Ren-Roros-Digital/checkstate
fix: check if $state -eq $true
2 parents 5b29e33 + cc56064 commit 8fc6150

13 files changed

Lines changed: 125 additions & 116 deletions

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ function Invoke-CIPPStandardActivityBasedTimeout {
4242
# Backwards compatibility for v5.7.0 and older
4343
if ($null -eq $Settings.timeout ) { $Settings.timeout = '01:00:00' }
4444

45-
$State = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies' -tenantid $tenant
46-
$StateIsCorrect = $State.definition -like "*$($Settings.timeout)*"
45+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies' -tenantid $tenant
46+
$StateIsCorrect = if ($CurrentState.definition -like "*$($Settings.timeout)*") { $true } else { $false }
4747

4848
If ($Settings.remediate -eq $true) {
4949
try {
50-
if (!$StateIsCorrect) {
50+
if ($StateIsCorrect -eq $true) {
51+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is already enabled and set to $($Settings.timeout)" -sev Info
52+
} else {
5153
$PolicyTemplate = @{
5254
displayName = 'DefaultTimeoutPolicy'
5355
isOrganizationDefault = $true
@@ -58,27 +60,24 @@ function Invoke-CIPPStandardActivityBasedTimeout {
5860
$body = ConvertTo-Json -InputObject $PolicyTemplate -Depth 10 -Compress
5961

6062
# Switch between parameter sets if the policy already exists
61-
if ($null -eq $State.id) {
63+
if ($null -eq $CurrentState.id) {
6264
$RequestType = 'POST'
6365
$URI = 'https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies'
6466
} else {
6567
$RequestType = 'PATCH'
66-
$URI = "https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies/$($State.id)"
68+
$URI = "https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies/$($CurrentState.id)"
6769
}
6870
New-GraphPostRequest -tenantid $tenant -Uri $URI -Type $RequestType -Body $body -ContentType 'application/json'
6971
Write-LogMessage -API 'Standards' -tenant $tenant -message "Enabled Activity Based Timeout with a value of $($Settings.timeout)" -sev Info
70-
} else {
71-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is already enabled and set to $($Settings.timeout)" -sev Info
7272
}
7373
} catch {
74-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
75-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to enable Activity Based Timeout a value of $($Settings.timeout). Error: $ErrorMessage" -sev Error
74+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to enable Activity Based Timeout a value of $($Settings.timeout)." -sev Error -LogData $_
7675
}
7776
}
7877

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

81-
if ($StateIsCorrect) {
80+
if ($StateIsCorrect -eq $true) {
8281
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is enabled and set to $($Settings.timeout)" -sev Info
8382
} else {
8483
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is not set to $($Settings.timeout)" -sev Alert

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@ 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+
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'Email' -Enabled $false
4040
}
4141
}
4242

4343
if ($Settings.alert -eq $true) {
44-
if ($State) {
44+
if ($StateIsCorrect -eq $true) {
4545
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Email authentication method is enabled' -sev Alert
4646
} else {
4747
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Email authentication method is not enabled' -sev Info
4848
}
4949
}
5050

5151
if ($Settings.report -eq $true) {
52-
Add-CIPPBPAField -FieldName 'DisableEmail' -FieldValue $State -StoreAs bool -Tenant $tenant
52+
Add-CIPPBPAField -FieldName 'DisableEmail' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5353
}
5454
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@ 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+
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'SMS' -Enabled $false
4040
}
4141
}
4242

4343
if ($Settings.alert -eq $true) {
44-
if ($State) {
44+
if ($StateIsCorrect -eq $true) {
4545
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SMS authentication method is enabled' -sev Alert
4646
} else {
4747
Write-LogMessage -API 'Standards' -tenant $tenant -message 'SMS authentication method is not enabled' -sev Info
4848
}
4949
}
5050

5151
if ($Settings.report -eq $true) {
52-
Add-CIPPBPAField -FieldName 'DisableSMS' -FieldValue $State -StoreAs bool -Tenant $tenant
52+
Add-CIPPBPAField -FieldName 'DisableSMS' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5353
}
5454
}

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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@ 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+
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'Voice' -Enabled $false
4040
}
4141
}
4242

4343
if ($Settings.alert -eq $true) {
44-
if ($State) {
44+
if ($StateIsCorrect -eq $true) {
4545
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Voice authentication method is enabled' -sev Alert
4646
} else {
4747
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Voice authentication method is not enabled' -sev Info
4848
}
4949
}
5050

5151
if ($Settings.report -eq $true) {
52-
Add-CIPPBPAField -FieldName 'DisableVoice' -FieldValue $State -StoreAs bool -Tenant $tenant
52+
Add-CIPPBPAField -FieldName 'DisableVoice' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5353
}
5454
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,27 @@ 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+
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'x509Certificate' -Enabled $false
4040
}
4141
}
4242

4343
if ($Settings.alert -eq $true) {
44-
if ($State) {
44+
if ($StateIsCorrect -eq $true) {
4545
Write-LogMessage -API 'Standards' -tenant $tenant -message 'x509Certificate authentication method is enabled' -sev Alert
4646
} else {
4747
Write-LogMessage -API 'Standards' -tenant $tenant -message 'x509Certificate authentication method is not enabled' -sev Info
4848
}
4949
}
5050

5151
if ($Settings.report -eq $true) {
52-
Add-CIPPBPAField -FieldName 'Disablex509Certificate' -FieldValue $State -StoreAs bool -Tenant $tenant
52+
Add-CIPPBPAField -FieldName 'Disablex509Certificate' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5353
}
5454

5555
}

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,26 @@ 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 {
4039
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'Fido2' -Enabled $true
4140
}
4241
}
4342

44-
4543
if ($Settings.alert -eq $true) {
46-
47-
if ($State) {
44+
if ($StateIsCorrect -eq $true) {
4845
Write-LogMessage -API 'Standards' -tenant $tenant -message 'FIDO2 Support is enabled' -sev Info
4946
} else {
5047
Write-LogMessage -API 'Standards' -tenant $tenant -message 'FIDO2 Support is not enabled' -sev Alert
5148
}
5249
}
5350

5451
if ($Settings.report -eq $true) {
55-
Add-CIPPBPAField -FieldName 'EnableFIDO2' -FieldValue $State -StoreAs bool -Tenant $tenant
52+
Add-CIPPBPAField -FieldName 'EnableFIDO2' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5653
}
57-
5854
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,26 @@ 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 {
4039
Set-CIPPAuthenticationPolicy -Tenant $tenant -APIName 'Standards' -AuthenticationMethodId 'HardwareOath' -Enabled $true
4140
}
4241
}
4342

4443
if ($Settings.alert -eq $true) {
45-
46-
if ($State) {
44+
if ($StateIsCorrect -eq $true) {
4745
Write-LogMessage -API 'Standards' -tenant $tenant -message 'HardwareOAuth Support is enabled' -sev Info
4846
} else {
4947
Write-LogMessage -API 'Standards' -tenant $tenant -message 'HardwareOAuth Support is not enabled' -sev Alert
5048
}
5149
}
5250

5351
if ($Settings.report -eq $true) {
54-
Add-CIPPBPAField -FieldName 'EnableHardwareOAuth' -FieldValue $State -StoreAs bool -Tenant $tenant
52+
Add-CIPPBPAField -FieldName 'EnableHardwareOAuth' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
5553
}
5654
}

0 commit comments

Comments
 (0)