Skip to content

Commit 10cd5ae

Browse files
Merge pull request KelvinTegelaar#1605 from kris6673/fix-ap-profile-all-devices
Fix AP profile assignment bug and improve casing consistency
2 parents 8653614 + 123f280 commit 10cd5ae

File tree

3 files changed

+53
-59
lines changed

3 files changed

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

3-
Function Invoke-AddAutopilotConfig {
3+
function Invoke-AddAutopilotConfig {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -14,42 +14,34 @@ Function Invoke-AddAutopilotConfig {
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-
$AssignTo = if ($request.body.Assignto -ne 'on') { $request.body.Assignto }
23-
$Profbod = [pscustomobject]$Request.body
24-
$usertype = if ($Profbod.NotLocalAdmin -eq 'true') { 'standard' } else { 'administrator' }
25-
$DeploymentMode = if ($profbod.DeploymentMode -eq 'true') { 'shared' } else { 'singleUser' }
18+
$Tenants = $Request.Body.selectedTenants.value
19+
$Profbod = [pscustomobject]$Request.Body
20+
$UserType = if ($Profbod.NotLocalAdmin -eq 'true') { 'standard' } else { 'administrator' }
21+
$DeploymentMode = if ($Profbod.DeploymentMode -eq 'true') { 'shared' } else { 'singleUser' }
2622
$profileParams = @{
27-
displayname = $request.body.Displayname
28-
description = $request.body.Description
29-
usertype = $usertype
23+
DisplayName = $Request.Body.DisplayName
24+
Description = $Request.Body.Description
25+
UserType = $UserType
3026
DeploymentMode = $DeploymentMode
31-
assignto = $AssignTo
32-
devicenameTemplate = $Profbod.deviceNameTemplate
33-
allowWhiteGlove = $Profbod.allowWhiteGlove
34-
CollectHash = $Profbod.collectHash
35-
hideChangeAccount = $Profbod.hideChangeAccount
36-
hidePrivacy = $Profbod.hidePrivacy
37-
hideTerms = $Profbod.hideTerms
27+
AssignTo = $Request.Body.Assignto
28+
DeviceNameTemplate = $Profbod.DeviceNameTemplate
29+
AllowWhiteGlove = $Profbod.allowWhiteGlove
30+
CollectHash = $Profbod.CollectHash
31+
HideChangeAccount = $Profbod.HideChangeAccount
32+
HidePrivacy = $Profbod.HidePrivacy
33+
HideTerms = $Profbod.HideTerms
3834
Autokeyboard = $Profbod.Autokeyboard
3935
Language = $ProfBod.languages.value
4036
}
41-
$results = foreach ($Tenant in $tenants) {
42-
$profileParams['tenantFilter'] = $Tenant
37+
$Results = foreach ($tenant in $Tenants) {
38+
$profileParams['tenantFilter'] = $tenant
4339
Set-CIPPDefaultAPDeploymentProfile @profileParams
4440
}
45-
$body = [pscustomobject]@{'Results' = $results }
4641

4742
# Associate values to output bindings by calling 'Push-OutputBinding'.
4843
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
4944
StatusCode = [HttpStatusCode]::OK
50-
Body = $body
45+
Body = @{'Results' = $Results }
5146
})
52-
53-
54-
5547
}
Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
function Set-CIPPDefaultAPDeploymentProfile {
22
[CmdletBinding(SupportsShouldProcess = $true)]
33
param(
4-
$tenantFilter,
5-
$displayName,
6-
$description,
7-
$devicenameTemplate,
8-
$allowWhiteGlove,
4+
$TenantFilter,
5+
$DisplayName,
6+
$Description,
7+
$DeviceNameTemplate,
8+
$AllowWhiteGlove,
99
$CollectHash,
10-
$userType,
10+
$UserType,
1111
$DeploymentMode,
12-
$hideChangeAccount,
12+
$HideChangeAccount,
1313
$AssignTo,
14-
$hidePrivacy,
15-
$hideTerms,
14+
$HidePrivacy,
15+
$HideTerms,
1616
$AutoKeyboard,
1717
$Headers,
1818
$Language = 'os-default',
@@ -24,65 +24,66 @@ function Set-CIPPDefaultAPDeploymentProfile {
2424
try {
2525
$ObjBody = [pscustomobject]@{
2626
'@odata.type' = '#microsoft.graph.azureADWindowsAutopilotDeploymentProfile'
27-
'displayName' = "$($displayName)"
28-
'description' = "$($description)"
29-
'deviceNameTemplate' = "$($devicenameTemplate)"
27+
'displayName' = "$($DisplayName)"
28+
'description' = "$($Description)"
29+
'deviceNameTemplate' = "$($DeviceNameTemplate)"
3030
'language' = "$($Language)"
31-
'enableWhiteGlove' = $([bool]($allowWhiteGlove))
31+
'enableWhiteGlove' = $([bool]($AllowWhiteGlove))
3232
'deviceType' = 'windowsPc'
3333
'extractHardwareHash' = $([bool]($CollectHash))
3434
'roleScopeTagIds' = @()
3535
'hybridAzureADJoinSkipConnectivityCheck' = $false
36-
'outOfBoxExperienceSetting' = @{
37-
'deviceUsageType' = "$DeploymentMode"
38-
'escapeLinkHidden' = $([bool]($hideChangeAccount))
39-
'privacySettingsHidden' = $([bool]($hidePrivacy))
40-
'eulaHidden' = $([bool]($hideTerms))
41-
'userType' = "$userType"
36+
'outOfBoxExperienceSetting' = @{
37+
'deviceUsageType' = "$DeploymentMode"
38+
'escapeLinkHidden' = $([bool]($HideChangeAccount))
39+
'privacySettingsHidden' = $([bool]($HidePrivacy))
40+
'eulaHidden' = $([bool]($HideTerms))
41+
'userType' = "$UserType"
4242
'keyboardSelectionPageSkipped' = $([bool]($AutoKeyboard))
4343
}
4444
}
4545
$Body = ConvertTo-Json -InputObject $ObjBody
4646

47-
$Profiles = New-GraphGETRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles' -tenantid $tenantFilter | Where-Object -Property displayName -EQ $displayName
47+
$Profiles = New-GraphGETRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles' -tenantid $TenantFilter | Where-Object -Property displayName -EQ $DisplayName
4848
if ($Profiles.count -gt 1) {
4949
$Profiles | ForEach-Object {
5050
if ($_.id -ne $Profiles[0].id) {
5151
if ($PSCmdlet.ShouldProcess($_.displayName, 'Delete duplicate Autopilot profile')) {
52-
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles/$($_.id)" -tenantid $tenantFilter -type DELETE
53-
Write-LogMessage -Headers $User -API $APIName -tenant $($tenantFilter) -message "Deleted duplicate Autopilot profile $($displayName)" -Sev 'Info'
52+
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles/$($_.id)" -tenantid $TenantFilter -type DELETE
53+
Write-LogMessage -Headers $User -API $APIName -tenant $($TenantFilter) -message "Deleted duplicate Autopilot profile $($DisplayName)" -Sev 'Info'
5454
}
5555
}
5656
}
5757
$Profiles = $Profiles[0]
5858
}
5959
if (!$Profiles) {
60-
if ($PSCmdlet.ShouldProcess($displayName, 'Add Autopilot profile')) {
60+
if ($PSCmdlet.ShouldProcess($DisplayName, 'Add Autopilot profile')) {
6161
$Type = 'Add'
62-
$GraphRequest = New-GraphPostRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles' -body $body -tenantid $tenantFilter
63-
Write-LogMessage -Headers $User -API $APIName -tenant $($tenantFilter) -message "Added Autopilot profile $($displayName)" -Sev 'Info'
62+
$GraphRequest = New-GraphPostRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles' -body $Body -tenantid $TenantFilter
63+
Write-LogMessage -Headers $User -API $APIName -tenant $($TenantFilter) -message "Added Autopilot profile $($DisplayName)" -Sev 'Info'
6464
}
6565
} else {
6666
$Type = 'Edit'
67-
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles/$($Profiles.id)" -tenantid $tenantFilter -body $body -type PATCH
67+
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles/$($Profiles.id)" -tenantid $TenantFilter -body $Body -type PATCH
6868
$GraphRequest = $Profiles | Select-Object -Last 1
6969
}
7070

7171
if ($AssignTo -eq $true) {
7272
$AssignBody = '{"target":{"@odata.type":"#microsoft.graph.allDevicesAssignmentTarget"}}'
73-
if ($PSCmdlet.ShouldProcess($AssignTo, "Assign Autopilot profile $displayName")) {
73+
if ($PSCmdlet.ShouldProcess($AssignTo, "Assign Autopilot profile $DisplayName")) {
7474
#Get assignments
75-
$Assignments = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles/$($GraphRequest.id)/assignments" -tenantid $tenantFilter
75+
$Assignments = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles/$($GraphRequest.id)/assignments" -tenantid $TenantFilter
7676
if (!$Assignments) {
77-
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles/$($GraphRequest.id)/assignments" -tenantid $tenantFilter -type POST -body $AssignBody
77+
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles/$($GraphRequest.id)/assignments" -tenantid $TenantFilter -type POST -body $AssignBody
7878
}
79-
Write-LogMessage -Headers $User -API $APIName -tenant $tenantFilter -message "Assigned autopilot profile $($displayName) to $AssignTo" -Sev 'Info'
79+
Write-LogMessage -Headers $User -API $APIName -tenant $TenantFilter -message "Assigned autopilot profile $($DisplayName) to $AssignTo" -Sev 'Info'
8080
}
8181
}
82-
"Successfully $($Type)ed profile for $tenantFilter"
82+
"Successfully $($Type)ed profile for $TenantFilter"
8383
} catch {
8484
$ErrorMessage = Get-CippException -Exception $_
85-
Write-LogMessage -Headers $User -API $APIName -tenant $tenantFilter -message "Failed $($Type)ing Autopilot Profile $($displayName). Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
86-
throw "Failed to add profile for $($tenantFilter): $($ErrorMessage.NormalizedError)"
85+
$Result = "Failed $($Type)ing Autopilot Profile $($DisplayName). Error: $($ErrorMessage.NormalizedError)"
86+
Write-LogMessage -Headers $User -API $APIName -tenant $TenantFilter -message $Result -Sev 'Error' -LogData $ErrorMessage
87+
throw $Result
8788
}
8889
}

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"endswith",
2121
"entra",
2222
"Entra",
23+
"eula",
2324
"exploitability",
2425
"gdap",
2526
"GDAP",

0 commit comments

Comments
 (0)