@@ -43,42 +43,44 @@ function Invoke-CIPPStandardAutopilotProfile {
4343
4444 # Get the current configuration
4545 try {
46+ # Replace variables in displayname to prevent duplicates
47+ $DisplayName = Get-CIPPTextReplacement - Text $Settings.DisplayName - TenantFilter $Tenant
48+
4649 $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
50+ Where-Object { $_.displayName -eq $DisplayName } |
51+ Select-Object - Property displayName, description, deviceNameTemplate, language, enableWhiteGlove, extractHardwareHash, outOfBoxExperienceSetting, preprovisioningAllowed
4952
5053 if ($Settings.NotLocalAdmin -eq $true ) { $userType = ' Standard' } else { $userType = ' Administrator' }
5154 if ($Settings.SelfDeployingMode -eq $true ) { $DeploymentMode = ' shared' } else { $DeploymentMode = ' singleUser' }
52- if ($Settings.AllowWhiteGlove -eq $true ) {$Settings.HideChangeAccount = $true }
55+ if ($Settings.AllowWhiteGlove -eq $true ) { $Settings.HideChangeAccount = $true }
5356
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 {
57+ $StateIsCorrect = ($CurrentConfig.displayName -eq $DisplayName ) -and
58+ ($CurrentConfig.description -eq $Settings.Description ) -and
59+ ($CurrentConfig.deviceNameTemplate -eq $Settings.DeviceNameTemplate ) -and
60+ ([string ]::IsNullOrWhiteSpace($CurrentConfig.language ) -and [string ]::IsNullOrWhiteSpace($Settings.Languages.value ) -or $CurrentConfig.language -eq $Settings.Languages.value ) -and
61+ ($CurrentConfig.enableWhiteGlove -eq $Settings.AllowWhiteGlove ) -and
62+ ($CurrentConfig.extractHardwareHash -eq $Settings.CollectHash ) -and
63+ ($CurrentConfig.outOfBoxExperienceSetting.deviceUsageType -eq $DeploymentMode ) -and
64+ ($CurrentConfig.outOfBoxExperienceSetting.escapeLinkHidden -eq $Settings.HideChangeAccount ) -and
65+ ($CurrentConfig.outOfBoxExperienceSetting.privacySettingsHidden -eq $Settings.HidePrivacy ) -and
66+ ($CurrentConfig.outOfBoxExperienceSetting.eulaHidden -eq $Settings.HideTerms ) -and
67+ ($CurrentConfig.outOfBoxExperienceSetting.userType -eq $userType ) -and
68+ ($CurrentConfig.outOfBoxExperienceSetting.keyboardSelectionPageSkipped -eq $Settings.AutoKeyboard )
69+ } catch {
6870 $ErrorMessage = Get-NormalizedError - Message $_.Exception.Message
6971 Write-LogMessage - API ' Standards' - tenant $Tenant - message " Failed to check Autopilot profile: $ErrorMessage " - sev Error
7072 $StateIsCorrect = $false
7173 }
7274
7375 # Remediate if the state is not correct
74- If ($Settings.remediate -eq $true ) {
76+ if ($Settings.remediate -eq $true ) {
7577 if ($StateIsCorrect -eq $true ) {
76- Write-LogMessage - API ' Standards' - tenant $Tenant - message " Autopilot profile '$ ( $Settings . DisplayName ) ' already exists" - sev Info
78+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Autopilot profile '$ ( $DisplayName ) ' already exists" - sev Info
7779 } else {
7880 try {
7981 $Parameters = @ {
8082 tenantFilter = $Tenant
81- displayName = $Settings . DisplayName
83+ displayName = $DisplayName
8284 description = $Settings.Description
8385 userType = $userType
8486 DeploymentMode = $DeploymentMode
@@ -95,9 +97,9 @@ function Invoke-CIPPStandardAutopilotProfile {
9597
9698 Set-CIPPDefaultAPDeploymentProfile @Parameters
9799 if ($null -eq $CurrentConfig ) {
98- Write-LogMessage - API ' Standards' - tenant $Tenant - message " Created Autopilot profile '$ ( $Settings . DisplayName ) '" - sev Info
100+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Created Autopilot profile '$ ( $DisplayName ) '" - sev Info
99101 } else {
100- Write-LogMessage - API ' Standards' - tenant $Tenant - message " Updated Autopilot profile '$ ( $Settings . DisplayName ) '" - sev Info
102+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Updated Autopilot profile '$ ( $DisplayName ) '" - sev Info
101103 }
102104 } catch {
103105 $ErrorMessage = Get-NormalizedError - Message $_.Exception.Message
@@ -108,19 +110,19 @@ function Invoke-CIPPStandardAutopilotProfile {
108110 }
109111
110112 # Report
111- If ($Settings.report -eq $true ) {
113+ if ($Settings.report -eq $true ) {
112114 $FieldValue = $StateIsCorrect -eq $true ? $true : $CurrentConfig
113115 Set-CIPPStandardsCompareField - FieldName ' standards.AutopilotProfile' - FieldValue $FieldValue - TenantFilter $Tenant
114116 Add-CIPPBPAField - FieldName ' AutopilotProfile' - FieldValue [bool ]$StateIsCorrect - StoreAs bool - Tenant $Tenant
115117 }
116118
117119 # 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
120+ if ($Settings.alert -eq $true ) {
121+ if ($StateIsCorrect -eq $true ) {
122+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Autopilot profile '$ ( $DisplayName ) ' exists" - sev Info
121123 } 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+ Write-StandardsAlert - message " Autopilot profile '$ ( $DisplayName ) ' do not match expected configuration" - object $CurrentConfig - tenant $Tenant - standardName ' AutopilotProfile' - standardId $Settings.standardId
125+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Autopilot profile '$ ( $DisplayName ) ' do not match expected configuration" - sev Info
124126 }
125127 }
126128}
0 commit comments