Skip to content

Commit 6cdabc6

Browse files
Merge pull request #1405 from Ren-Roros-Digital/chore-AutopilotStatusPage
chore: fix up AutopilotStatusPage
2 parents 2a3c576 + 2744af7 commit 6cdabc6

File tree

2 files changed

+39
-53
lines changed

2 files changed

+39
-53
lines changed

Modules/CIPPCore/Public/Set-CIPPDefaultAPEnrollment.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function Set-CIPPDefaultAPEnrollment {
2323
'displayName' = 'All users and all devices'
2424
'description' = 'This is the default enrollment status screen configuration applied with the lowest priority to all users and all devices regardless of group membership.'
2525
'showInstallationProgress' = [bool]$ShowProgress
26-
'blockDeviceSetupRetryByUser' = ![bool]$blockDevice
26+
'blockDeviceSetupRetryByUser' = ![bool]$BlockDevice
2727
'allowDeviceResetOnInstallFailure' = [bool]$AllowReset
2828
'allowLogCollectionOnInstallFailure' = [bool]$EnableLog
2929
'customErrorMessage' = "$ErrorMessage"
@@ -35,16 +35,16 @@ function Set-CIPPDefaultAPEnrollment {
3535
'roleScopeTagIds' = @()
3636
}
3737
$Body = ConvertTo-Json -InputObject $ObjBody
38-
$ExistingStatusPage = (New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations' -tenantid $($TenantFilter)) | Where-Object { $_.id -like '*DefaultWindows10EnrollmentCompletionPageConfiguration' }
38+
$ExistingStatusPage = (New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations' -tenantid $TenantFilter) | Where-Object { $_.id -like '*DefaultWindows10EnrollmentCompletionPageConfiguration' }
3939

4040
if ($PSCmdlet.ShouldProcess($ExistingStatusPage.ID, 'Set Default Enrollment Status Page')) {
41-
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations/$($ExistingStatusPage.ID)" -body $body -Type PATCH -tenantid $($TenantFilter)
42-
"Successfully changed default enrollment status page for $($($TenantFilter))"
43-
Write-LogMessage -Headers $User -API $APINAME -tenant $($TenantFilter) -message "Added Autopilot Enrollment Status Page $($Displayname)" -Sev 'Info'
41+
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations/$($ExistingStatusPage.ID)" -body $Body -Type PATCH -tenantid $TenantFilter
42+
"Successfully changed default enrollment status page for $TenantFilter"
43+
Write-LogMessage -Headers $User -API $APIName -tenant $TenantFilter -message "Added Autopilot Enrollment Status Page $($ExistingStatusPage.displayName)" -Sev 'Info'
4444
}
4545
} catch {
4646
$ErrorMessage = Get-CippException -Exception $_
47-
Write-LogMessage -Headers $User -API $APINAME -tenant $($TenantFilter) -message "Failed adding Autopilot Enrollment Status Page $($Displayname). Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
48-
throw "Failed to change default enrollment status page for $($($TenantFilter)): $($ErrorMessage.NormalizedError)"
47+
Write-LogMessage -Headers $User -API $APIName -tenant $TenantFilter -message "Failed adding Autopilot Enrollment Status Page $($ExistingStatusPage.displayName). Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
48+
throw "Failed to change default enrollment status page for $($TenantFilter): $($ErrorMessage.NormalizedError)"
4949
}
5050
}

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

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,33 @@ function Invoke-CIPPStandardAutopilotStatusPage {
3636
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/
3737
#>
3838
param($Tenant, $Settings)
39+
40+
# Get current Autopilot enrollment status page configuration
41+
try {
42+
$CurrentConfig = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations?`$expand=assignments&orderBy=priority&`$filter=deviceEnrollmentConfigurationType eq 'windows10EnrollmentCompletionPageConfiguration' and priority eq 0" -tenantid $Tenant |
43+
Select-Object -Property id, displayName, priority, showInstallationProgress, blockDeviceSetupRetryByUser, allowDeviceResetOnInstallFailure, allowLogCollectionOnInstallFailure, customErrorMessage, installProgressTimeoutInMinutes, allowDeviceUseOnInstallFailure, trackInstallProgressForAutopilotOnly
44+
45+
$StateIsCorrect = ($CurrentConfig.installProgressTimeoutInMinutes -eq $Settings.TimeOutInMinutes) -and
46+
($CurrentConfig.customErrorMessage -eq $Settings.ErrorMessage) -and
47+
($CurrentConfig.showInstallationProgress -eq $Settings.ShowProgress) -and
48+
($CurrentConfig.allowLogCollectionOnInstallFailure -eq $Settings.EnableLog) -and
49+
($CurrentConfig.trackInstallProgressForAutopilotOnly -eq $Settings.OBEEOnly) -and
50+
($CurrentConfig.blockDeviceSetupRetryByUser -eq !$Settings.BlockDevice) -and
51+
($CurrentConfig.allowDeviceResetOnInstallFailure -eq $Settings.AllowReset) -and
52+
($CurrentConfig.allowDeviceUseOnInstallFailure -eq $Settings.AllowFail)
53+
} catch {
54+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
55+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to check Autopilot Enrollment Status Page: $ErrorMessage" -sev Error
56+
$StateIsCorrect = $false
57+
}
58+
59+
# Remediate if the state is not correct
3960
If ($Settings.remediate -eq $true) {
40-
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'APESP'
41-
if ($Rerun -eq $true) {
42-
exit 0
43-
}
4461
try {
4562
$Parameters = @{
4663
TenantFilter = $Tenant
4764
ShowProgress = $Settings.ShowProgress
48-
BlockDevice = $Settings.blockDevice
65+
BlockDevice = $Settings.BlockDevice
4966
AllowReset = $Settings.AllowReset
5067
EnableLog = $Settings.EnableLog
5168
ErrorMessage = $Settings.ErrorMessage
@@ -61,51 +78,20 @@ function Invoke-CIPPStandardAutopilotStatusPage {
6178
}
6279
}
6380

64-
# Get current Autopilot enrollment status page configuration
65-
try {
66-
$CurrentConfig = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations?`$filter=startswith(displayName,'Windows Autopilot')" -tenantid $Tenant
67-
68-
# Check if the enrollment status page exists
69-
$ESPConfig = $CurrentConfig.value | Where-Object { $_.displayName -like '*Enrollment Status Page*' }
70-
71-
$ESPConfigured = $null -ne $ESPConfig
72-
73-
# Check if settings match what's expected
74-
$SettingsMismatch = $false
75-
$MismatchDetails = @{}
76-
77-
if ($ESPConfigured) {
78-
# Check timeout setting
79-
if ($ESPConfig.priority -ne 0) {
80-
$SettingsMismatch = $true
81-
$MismatchDetails.Priority = @{Expected = 0; Actual = $ESPConfig.priority }
82-
}
83-
84-
}
85-
86-
$StateIsCorrect = $ESPConfigured -and (-not $SettingsMismatch)
87-
} catch {
88-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
89-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to check Autopilot Enrollment Status Page: $ErrorMessage" -sev Error
90-
$StateIsCorrect = $false
91-
}
92-
81+
# Report
9382
if ($Settings.report -eq $true) {
94-
$state = $StateIsCorrect -eq $true ? $true : $StateIsCorrect
95-
Set-CIPPStandardsCompareField -FieldName 'standards.AutopilotStatusPage' -FieldValue $state -TenantFilter $tenant
96-
Add-CIPPBPAField -FieldName 'AutopilotStatusPage' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
83+
$FieldValue = $StateIsCorrect -eq $true ? $true : $CurrentConfig
84+
Set-CIPPStandardsCompareField -FieldName 'standards.AutopilotStatusPage' -FieldValue $FieldValue -TenantFilter $Tenant
85+
Add-CIPPBPAField -FieldName 'AutopilotStatusPage' -FieldValue [bool]$StateIsCorrect -StoreAs bool -Tenant $Tenant
9786
}
9887

99-
if ($Settings.alert) {
100-
if (!$ESPConfigured) {
101-
Write-StandardsAlert -message 'Autopilot Enrollment Status Page is not configured' -object @{} -tenant $Tenant -standardName 'AutopilotStatusPage' -standardId $Settings.standardId
102-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Autopilot Enrollment Status Page is not configured' -sev Info
103-
} elseif ($SettingsMismatch) {
104-
Write-StandardsAlert -message 'Autopilot Enrollment Status Page settings do not match expected configuration' -object $MismatchDetails -tenant $Tenant -standardName 'AutopilotStatusPage' -standardId $Settings.standardId
105-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Autopilot Enrollment Status Page settings do not match expected configuration' -sev Info
88+
# Alert
89+
if ($Settings.alert -eq $true) {
90+
if ($StateIsCorrect -eq $true) {
91+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Autopilot Enrollment Status Page is configured correctly' -sev Info
10692
} else {
107-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Autopilot Enrollment Status Page is configured correctly' -sev Info
93+
Write-StandardsAlert -message 'Autopilot Enrollment Status Page settings do not match expected configuration' -object $CurrentConfig -tenant $Tenant -standardName 'AutopilotStatusPage' -standardId $Settings.standardId
94+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Autopilot Enrollment Status Page settings do not match expected configuration' -sev Info
10895
}
10996
}
110-
11197
}

0 commit comments

Comments
 (0)