From cfef17571ac7b4a5c5102f3af8ce5aa0a1b98fa9 Mon Sep 17 00:00:00 2001 From: Johan Dahlbom Date: Fri, 5 Jan 2024 11:16:57 +0000 Subject: [PATCH] sort and handle resources with only one api version in the array --- src/internal/functions/ConvertTo-AzOpsState.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/internal/functions/ConvertTo-AzOpsState.ps1 b/src/internal/functions/ConvertTo-AzOpsState.ps1 index 5e8a516f..7c85f1af 100644 --- a/src/internal/functions/ConvertTo-AzOpsState.ps1 +++ b/src/internal/functions/ConvertTo-AzOpsState.ps1 @@ -226,13 +226,13 @@ Write-PSFMessage -Level Verbose -String 'ConvertTo-AzOpsState.GenerateTemplate.ApiVersion' -StringValues $resourceType, $apiVersions -FunctionName 'ConvertTo-AzOpsState' # Handle GA/Preview API versions - $gaApiVersion = $apiVersions | Where-Object {$_ -match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'} - $preApiVersion = $apiVersions | Where-Object {$_ -notmatch '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'} + $gaApiVersion = $apiVersions | Where-Object {$_ -match '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'} | Sort-Object -Descending + $preApiVersion = $apiVersions | Where-Object {$_ -notmatch '^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$'} | Sort-Object -Descending if ($null -eq $gaApiVersion) { - $apiVersion = $preApiVersion[0] + $apiVersion = $preApiVersion | Select-Object -First 1 } else { - $apiVersion = $gaApiVersion[0] + $apiVersion = $gaApiVersion | Select-Object -First 1 } $object.resources[0].apiVersion = $apiVersion