@@ -40,49 +40,49 @@ function Invoke-CIPPStandardAutopilotProfile {
4040 https://docs.cipp.app/user-documentation/tenant/standards/list-standards/
4141 #>
4242 param ($Tenant , $Settings )
43- # #$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'APConfig'
4443
45- # Check if profile exists
46- $ProfileExists = $false
44+ # Get the current configuration
4745 try {
48- $Profiles = New-GraphGetRequest - uri ' https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles' - tenantid $Tenant
49- $ProfileExists = ($Profiles.displayName -contains $settings.DisplayName )
50- } catch {
51- $ErrorMessage = Get-NormalizedError - Message $_.Exception.Message
52- Write-LogMessage - API ' Standards' - tenant $tenant - message " Failed to check Autopilot profiles: $ErrorMessage " - sev ' Error'
53- }
46+ $CurrentConfig = New-GraphGetRequest - uri ' https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles' - tenantid $Tenant |
47+ Where-Object { $_.displayName -eq $Settings.DisplayName } |
48+ Select-Object - Property displayName, description, deviceNameTemplate, language, enableWhiteGlove, extractHardwareHash, outOfBoxExperienceSetting, preprovisioningAllowed
5449
55- if ($Settings.report -eq $true ) {
56- $state = $ProfileExists -eq $true ? $true : $ProfileExists
57- Set-CIPPStandardsCompareField - FieldName ' standards.AutopilotProfile' - FieldValue $state - TenantFilter $tenant
58- Add-CIPPBPAField - FieldName ' AutopilotProfile' - FieldValue $ProfileExists - StoreAs bool - Tenant $tenant
59- }
50+ if ($Settings.NotLocalAdmin -eq $true ) { $userType = ' Standard' } else { $userType = ' Administrator' }
51+ if ($Settings.SelfDeployingMode -eq $true ) { $DeploymentMode = ' shared' } else { $DeploymentMode = ' singleUser' }
52+ if ($Settings.AllowWhiteGlove -eq $true ) {$Settings.HideChangeAccount = $true }
6053
61- if ($Settings.alert -eq $true ) {
62- if ($ProfileExists ) {
63- Write-LogMessage - API ' Standards' - tenant $tenant - message " Autopilot profile '$ ( $settings.DisplayName ) ' exists" - sev Info
64- } else {
65- Write-StandardsAlert - message " Autopilot profile '$ ( $settings.DisplayName ) ' does not exist" - object @ {ProfileName = $settings.DisplayName } - tenant $tenant - standardName ' AutopilotProfile' - standardId $Settings.standardId
66- Write-LogMessage - API ' Standards' - tenant $tenant - message " Autopilot profile '$ ( $settings.DisplayName ) ' does not exist" - sev Info
67- }
54+ $StateIsCorrect = ($CurrentConfig.displayName -eq $Settings.DisplayName ) -and
55+ ($CurrentConfig.description -eq $Settings.Description ) -and
56+ ($CurrentConfig.deviceNameTemplate -eq $Settings.DeviceNameTemplate ) -and
57+ ([string ]::IsNullOrWhiteSpace($CurrentConfig.language ) -and [string ]::IsNullOrWhiteSpace($Settings.Languages.value ) -or $CurrentConfig.language -eq $Settings.Languages.value ) -and
58+ ($CurrentConfig.enableWhiteGlove -eq $Settings.AllowWhiteGlove ) -and
59+ ($CurrentConfig.extractHardwareHash -eq $Settings.CollectHash ) -and
60+ ($CurrentConfig.outOfBoxExperienceSetting.deviceUsageType -eq $DeploymentMode ) -and
61+ ($CurrentConfig.outOfBoxExperienceSetting.escapeLinkHidden -eq $Settings.HideChangeAccount ) -and
62+ ($CurrentConfig.outOfBoxExperienceSetting.privacySettingsHidden -eq $Settings.HidePrivacy ) -and
63+ ($CurrentConfig.outOfBoxExperienceSetting.eulaHidden -eq $Settings.HideTerms ) -and
64+ ($CurrentConfig.outOfBoxExperienceSetting.userType -eq $userType ) -and
65+ ($CurrentConfig.outOfBoxExperienceSetting.keyboardSelectionPageSkipped -eq $Settings.AutoKeyboard )
66+ }
67+ catch {
68+ $ErrorMessage = Get-NormalizedError - Message $_.Exception.Message
69+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Failed to check Autopilot profile: $ErrorMessage " - sev Error
70+ $StateIsCorrect = $false
6871 }
6972
73+ # Remediate if the state is not correct
7074 If ($Settings.remediate -eq $true ) {
71- if ($ProfileExists ) {
72- Write-LogMessage - API ' Standards' - tenant $tenant - message " Autopilot profile '$ ( $settings .DisplayName ) ' already exists" - sev Info
75+ if ($StateIsCorrect -eq $true ) {
76+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Autopilot profile '$ ( $Settings .DisplayName ) ' already exists" - sev Info
7377 } else {
7478 try {
75- Write-Host $ ($settings | ConvertTo-Json - Depth 100 )
76- if ($settings.NotLocalAdmin -eq $true ) { $usertype = ' Standard' } else { $usertype = ' Administrator' }
77- $DeploymentMode = if ($settings.DeploymentMode -eq ' true' ) { ' shared' } else { ' singleUser' }
78-
7979 $Parameters = @ {
80- tenantFilter = $tenant
81- displayname = $settings .DisplayName
82- description = $settings .Description
83- usertype = $usertype
80+ tenantFilter = $Tenant
81+ displayName = $Settings .DisplayName
82+ description = $Settings .Description
83+ userType = $userType
8484 DeploymentMode = $DeploymentMode
85- assignto = $settings .AssignToAllDevices
85+ AssignTo = $Settings .AssignToAllDevices
8686 devicenameTemplate = $Settings.DeviceNameTemplate
8787 allowWhiteGlove = $Settings.AllowWhiteGlove
8888 CollectHash = $Settings.CollectHash
@@ -94,12 +94,33 @@ function Invoke-CIPPStandardAutopilotProfile {
9494 }
9595
9696 Set-CIPPDefaultAPDeploymentProfile @Parameters
97- Write-LogMessage - API ' Standards' - tenant $tenant - message " Created Autopilot profile '$ ( $settings.DisplayName ) '" - sev Info
97+ if ($null -eq $CurrentConfig ) {
98+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Created Autopilot profile '$ ( $Settings.DisplayName ) '" - sev Info
99+ } else {
100+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Updated Autopilot profile '$ ( $Settings.DisplayName ) '" - sev Info
101+ }
98102 } catch {
99103 $ErrorMessage = Get-NormalizedError - Message $_.Exception.Message
100- Write-LogMessage - API ' Standards' - tenant $tenant - message " Failed to create Autopilot profile: $ErrorMessage " - sev ' Error'
104+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Failed to create Autopilot profile: $ErrorMessage " - sev ' Error'
101105 throw $ErrorMessage
102106 }
103107 }
104108 }
109+
110+ # Report
111+ If ($Settings.report -eq $true ) {
112+ $FieldValue = $StateIsCorrect -eq $true ? $true : $CurrentConfig
113+ Set-CIPPStandardsCompareField - FieldName ' standards.AutopilotProfile' - FieldValue $FieldValue - TenantFilter $Tenant
114+ Add-CIPPBPAField - FieldName ' AutopilotProfile' - FieldValue [bool ]$StateIsCorrect - StoreAs bool - Tenant $Tenant
115+ }
116+
117+ # Alert
118+ If ($Settings.alert -eq $true ) {
119+ If ($StateIsCorrect -eq $true ) {
120+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Autopilot profile '$ ( $Settings.DisplayName ) ' exists" - sev Info
121+ } else {
122+ Write-StandardsAlert - message " Autopilot profile '$ ( $Settings.DisplayName ) ' do not match expected configuration" - object $CurrentConfig - tenant $Tenant - standardName ' AutopilotProfile' - standardId $Settings.standardId
123+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Autopilot profile '$ ( $Settings.DisplayName ) ' do not match expected configuration" - sev Info
124+ }
125+ }
105126}
0 commit comments