Skip to content

Commit b9eecf2

Browse files
authored
Merge pull request KelvinTegelaar#1609 from kris6673/esp-fix
Feat: Refactor and enhance enrollment functions with Windows updates option
2 parents 9c13efd + 8567bf9 commit b9eecf2

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-AddEnrollment {
3+
function Invoke-AddEnrollment {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -14,22 +14,29 @@ Function Invoke-AddEnrollment {
1414
$Headers = $Request.Headers
1515
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616

17-
18-
19-
2017
# Input bindings are passed in via param block.
21-
$Tenants = $Request.body.selectedTenants.value
22-
$Profbod = $Request.body
23-
$results = foreach ($Tenant in $tenants) {
24-
Set-CIPPDefaultAPEnrollment -TenantFilter $Tenant -ShowProgress $Profbod.ShowProgress -BlockDevice $Profbod.blockDevice -AllowReset $Profbod.AllowReset -EnableLog $Profbod.EnableLog -ErrorMessage $Profbod.ErrorMessage -TimeOutInMinutes $Profbod.TimeOutInMinutes -AllowFail $Profbod.AllowFail -OBEEOnly $Profbod.OBEEOnly
18+
$Tenants = $Request.Body.selectedTenants.value
19+
$Profbod = $Request.Body
20+
$Results = foreach ($Tenant in $Tenants) {
21+
$ParamSplat = @{
22+
TenantFilter = $Tenant
23+
ShowProgress = $Profbod.ShowProgress
24+
BlockDevice = $Profbod.blockDevice
25+
AllowReset = $Profbod.AllowReset
26+
EnableLog = $Profbod.EnableLog
27+
ErrorMessage = $Profbod.ErrorMessage
28+
TimeOutInMinutes = $Profbod.TimeOutInMinutes
29+
AllowFail = $Profbod.AllowFail
30+
OBEEOnly = $Profbod.OBEEOnly
31+
InstallWindowsUpdates = $Profbod.InstallWindowsUpdates
32+
}
33+
Set-CIPPDefaultAPEnrollment @ParamSplat
2534
}
2635

27-
$body = [pscustomobject]@{'Results' = $results }
28-
2936
# Associate values to output bindings by calling 'Push-OutputBinding'.
3037
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
3138
StatusCode = [HttpStatusCode]::OK
32-
Body = $body
39+
Body = @{'Results' = $Results }
3340
})
3441

3542
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Endpoint/Autopilot/Invoke-ListAutopilotconfig.ps1

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ListAutopilotconfig {
3+
function Invoke-ListAutopilotconfig {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -15,18 +15,16 @@ Function Invoke-ListAutopilotconfig {
1515
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616

1717

18-
19-
2018
# Interact with query parameters or the body of the request.
2119
$TenantFilter = $Request.Query.TenantFilter
22-
$userid = $Request.Query.UserID
2320
try {
24-
if ($request.query.type -eq 'ApProfile') {
21+
if ($Request.Query.type -eq 'ApProfile') {
2522
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles?`$expand=assignments" -tenantid $TenantFilter
2623
}
2724

28-
if ($request.query.type -eq 'ESP') {
29-
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations?`$expand=assignments" -tenantid $TenantFilter | Where-Object -Property '@odata.type' -EQ '#microsoft.graph.windows10EnrollmentCompletionPageConfiguration'
25+
if ($Request.Query.type -eq 'ESP') {
26+
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations?`$expand=assignments" -tenantid $TenantFilter |
27+
Where-Object -Property '@odata.type' -EQ '#microsoft.graph.windows10EnrollmentCompletionPageConfiguration'
3028
}
3129
$StatusCode = [HttpStatusCode]::OK
3230
} catch {

Modules/CIPPCore/Public/Set-CIPPDefaultAPEnrollment.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ function Set-CIPPDefaultAPEnrollment {
88
$EnableLog,
99
$ErrorMessage,
1010
$TimeOutInMinutes,
11+
$InstallWindowsUpdates,
1112
$AllowFail,
1213
$OBEEOnly,
1314
$Headers,
1415
$APIName = 'Add Default Enrollment Status Page'
1516
)
1617

17-
$User = $Request.Headers
18-
1918
try {
2019
$ObjBody = [pscustomobject]@{
2120
'@odata.type' = '#microsoft.graph.windows10EnrollmentCompletionPageConfiguration'
@@ -28,6 +27,7 @@ function Set-CIPPDefaultAPEnrollment {
2827
'allowLogCollectionOnInstallFailure' = [bool]$EnableLog
2928
'customErrorMessage' = "$ErrorMessage"
3029
'installProgressTimeoutInMinutes' = $TimeOutInMinutes
30+
'installQualityUpdates' = [bool]$InstallWindowsUpdates
3131
'allowDeviceUseOnInstallFailure' = [bool]$AllowFail
3232
'selectedMobileAppIds' = @()
3333
'trackInstallProgressForAutopilotOnly' = [bool]$OBEEOnly
@@ -40,11 +40,11 @@ function Set-CIPPDefaultAPEnrollment {
4040
if ($PSCmdlet.ShouldProcess($ExistingStatusPage.ID, 'Set Default Enrollment Status Page')) {
4141
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations/$($ExistingStatusPage.ID)" -body $Body -Type PATCH -tenantid $TenantFilter
4242
"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'
43+
Write-LogMessage -Headers $Headers -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 $($ExistingStatusPage.displayName). Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
47+
Write-LogMessage -Headers $Headers -API $APIName -tenant $TenantFilter -message "Failed adding Autopilot Enrollment Status Page $($ExistingStatusPage.displayName). Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
4848
throw "Failed to change default enrollment status page for $($TenantFilter): $($ErrorMessage.NormalizedError)"
4949
}
5050
}

0 commit comments

Comments
 (0)