Skip to content

Commit b187be2

Browse files
committed
fix: text replacement vars causing standard mismatch
fixes KelvinTegelaar/CIPP#4914 replace vars in push-cippstandard
1 parent 445df4a commit b187be2

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Standards/Push-CIPPStandard.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ function Push-CIPPStandard {
2020
Write-Information "Rerun is set to false. We'll be running $FunctionName"
2121
}
2222
try {
23-
& $FunctionName -Tenant $Item.Tenant -Settings $Item.Settings -ErrorAction Stop
23+
# Convert settings to JSON, replace %variables%, then convert back to object
24+
$SettingsJSON = $Item.Settings | ConvertTo-Json -Depth 10 -Compress
25+
if ($SettingsJSON -match '%') {
26+
$Settings = Get-CIPPTextReplacement -TenantFilter $Item.Tenant -Text $SettingsJSON | ConvertFrom-Json
27+
} else {
28+
$Settings = $Item.Settings
29+
}
30+
31+
& $FunctionName -Tenant $Item.Tenant -Settings $Settings -ErrorAction Stop
2432
Write-Information "Standard $($Standard) completed for tenant $($Tenant)"
2533
} catch {
2634
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Error running standard $($Standard) for tenant $($Tenant) - $($_.Exception.Message)" -sev Error -LogData (Get-CippException -Exception $_)

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ function Invoke-CIPPStandardAutopilotProfile {
4949
return $true
5050
} #we're done.
5151
try {
52-
# Replace variables in displayname to prevent duplicates
53-
$DisplayName = Get-CIPPTextReplacement -Text $Settings.DisplayName -TenantFilter $Tenant
54-
5552
$CurrentConfig = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles' -tenantid $Tenant |
56-
Where-Object { $_.displayName -eq $DisplayName } |
53+
Where-Object { $_.displayName -eq $Settings.DisplayName } |
5754
Select-Object -Property displayName, description, deviceNameTemplate, locale, preprovisioningAllowed, hardwareHashExtractionEnabled, outOfBoxExperienceSetting
5855

5956
if ($Settings.NotLocalAdmin -eq $true) { $userType = 'Standard' } else { $userType = 'Administrator' }
@@ -64,7 +61,7 @@ function Invoke-CIPPStandardAutopilotProfile {
6461
$DeploymentMode = 'singleUser'
6562
}
6663

67-
$StateIsCorrect = ($CurrentConfig.displayName -eq $DisplayName) -and
64+
$StateIsCorrect = ($CurrentConfig.displayName -eq $Settings.DisplayName) -and
6865
($CurrentConfig.description -eq $Settings.Description) -and
6966
($CurrentConfig.deviceNameTemplate -eq $Settings.DeviceNameTemplate) -and
7067
([string]::IsNullOrWhiteSpace($CurrentConfig.locale) -and [string]::IsNullOrWhiteSpace($Settings.Languages.value) -or $CurrentConfig.locale -eq $Settings.Languages.value) -and
@@ -84,12 +81,12 @@ function Invoke-CIPPStandardAutopilotProfile {
8481
# Remediate if the state is not correct
8582
if ($Settings.remediate -eq $true) {
8683
if ($StateIsCorrect -eq $true) {
87-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Autopilot profile '$($DisplayName)' already exists" -sev Info
84+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Autopilot profile '$($Settings.DisplayName)' already exists" -sev Info
8885
} else {
8986
try {
9087
$Parameters = @{
9188
tenantFilter = $Tenant
92-
displayName = $DisplayName
89+
displayName = $Settings.DisplayName
9390
description = $Settings.Description
9491
userType = $userType
9592
DeploymentMode = $DeploymentMode
@@ -106,9 +103,9 @@ function Invoke-CIPPStandardAutopilotProfile {
106103

107104
Set-CIPPDefaultAPDeploymentProfile @Parameters
108105
if ($null -eq $CurrentConfig) {
109-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Created Autopilot profile '$($DisplayName)'" -sev Info
106+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Created Autopilot profile '$($Settings.DisplayName)'" -sev Info
110107
} else {
111-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Updated Autopilot profile '$($DisplayName)'" -sev Info
108+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Updated Autopilot profile '$($Settings.DisplayName)'" -sev Info
112109
}
113110
} catch {
114111
$ErrorMessage = Get-CippException -Exception $_
@@ -128,10 +125,10 @@ function Invoke-CIPPStandardAutopilotProfile {
128125
# Alert
129126
if ($Settings.alert -eq $true) {
130127
if ($StateIsCorrect -eq $true) {
131-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Autopilot profile '$($DisplayName)' exists" -sev Info
128+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Autopilot profile '$($Settings.DisplayName)' exists" -sev Info
132129
} else {
133-
Write-StandardsAlert -message "Autopilot profile '$($DisplayName)' do not match expected configuration" -object $CurrentConfig -tenant $Tenant -standardName 'AutopilotProfile' -standardId $Settings.standardId
134-
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Autopilot profile '$($DisplayName)' do not match expected configuration" -sev Info
130+
Write-StandardsAlert -message "Autopilot profile '$($Settings.DisplayName)' do not match expected configuration" -object $CurrentConfig -tenant $Tenant -standardName 'AutopilotProfile' -standardId $Settings.standardId
131+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Autopilot profile '$($Settings.DisplayName)' do not match expected configuration" -sev Info
135132
}
136133
}
137134
}

0 commit comments

Comments
 (0)