Skip to content

Commit c82f0e2

Browse files
anwatherAnthony Watherston
and
Anthony Watherston
authored
Metadata order and parameter fixes (#942)
Co-authored-by: Anthony Watherston <Anthony.Watherston@microsoft.com>
1 parent 1be29e3 commit c82f0e2

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

Scripts/Helpers/Confirm-ParametersUsageMatches.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ function Confirm-ParametersUsageMatches {
4242

4343
$definedParameterValue = $definedParameter
4444
if (($null -ne $definedParameterValue.value) -and ((-not($uniqueKeys -contains "maintenanceConfigurationResourceId")) -or (-not($uniqueKeys -contains "AzurePatchRingmaintenanceConfigurationResourceId")))) {
45-
$definedParameterValue = $definedParameter.value
45+
if ($definedParameterValue -isnot [array]) {
46+
$definedParameterValue = $definedParameter.value
47+
}
4648
}
4749

4850
if (!(Confirm-ObjectValueEqualityDeep $existingParameterValue $definedParameterValue)) {

Scripts/Helpers/Out-PolicyExemptions.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ function Out-PolicyExemptions {
156156
if ($selectedArray -and $selectedArray.Count -gt 0) {
157157
$jsonArray += $selectedArray
158158
}
159+
# Logic to force the order of the Metadata property (DeployedBy first, then epacMetadata)
160+
foreach ($array in $jsonArray) {
161+
$meta = $array.Metadata
162+
$orderedMeta = [ordered]@{
163+
deployedBy = $meta['deployedBy']
164+
epacMetadata = $meta['epacMetadata']
165+
}
166+
$array.Metadata = $orderedMeta
167+
}
159168
$jsonFile = "$stem.$FileExtension"
160169
if (Test-Path $jsonFile) {
161170
Remove-Item $jsonFile
@@ -182,6 +191,17 @@ function Out-PolicyExemptions {
182191
if ($null -ne $selectedArray -and $selectedArray.Count -gt 0) {
183192
$excelArray += $selectedArray
184193
}
194+
# Logic to force the order of the Metadata property (DeployedBy first, then epacMetadata)
195+
foreach ($array in $excelArray) {
196+
$metaString = $array.Metadata
197+
$meta = $metaString | ConvertFrom-Json -Depth 100
198+
$orderedMeta = [ordered]@{
199+
deployedBy = $meta.deployedBy
200+
epacMetadata = $meta.epacMetadata
201+
}
202+
$orderedMetadata = (ConvertTo-Json $orderedMeta -Depth 100 -Compress).ToString()
203+
$array.Metadata = $orderedMetadata
204+
}
185205
$csvFile = "$stem.csv"
186206
if (Test-Path $csvFile) {
187207
Remove-Item $csvFile
@@ -224,6 +244,15 @@ function Out-PolicyExemptions {
224244
if ($selectedArray -and $selectedArray.Count -gt 0) {
225245
$jsonArray += $selectedArray
226246
}
247+
# Logic to force the order of the Metadata property (DeployedBy first, then epacMetadata)
248+
foreach ($array in $jsonArray) {
249+
$meta = $array.Metadata
250+
$orderedMeta = [ordered]@{
251+
deployedBy = $meta['deployedBy']
252+
epacMetadata = $meta['epacMetadata']
253+
}
254+
$array.Metadata = $orderedMeta
255+
}
227256
$jsonFile = "$stem.$FileExtension"
228257
if (Test-Path $jsonFile) {
229258
Remove-Item $jsonFile
@@ -252,6 +281,17 @@ function Out-PolicyExemptions {
252281
if ($null -ne $selectedArray -and $selectedArray.Count -gt 0) {
253282
$excelArray += $selectedArray
254283
}
284+
# Logic to force the order of the Metadata property (DeployedBy first, then epacMetadata)
285+
foreach ($array in $excelArray) {
286+
$metaString = $array.Metadata
287+
$meta = $metaString | ConvertFrom-Json -Depth 100
288+
$orderedMeta = [ordered]@{
289+
deployedBy = $meta.deployedBy
290+
epacMetadata = $meta.epacMetadata
291+
}
292+
$orderedMetadata = (ConvertTo-Json $orderedMeta -Depth 100 -Compress).ToString()
293+
$array.Metadata = $orderedMetadata
294+
}
255295
$csvFile = "$stem.csv"
256296
if (Test-Path $csvFile) {
257297
Remove-Item $csvFile

0 commit comments

Comments
 (0)