diff --git a/common/code-upgrade-samples/az/dynamic-parameters-test1.ps1 b/common/code-upgrade-samples/az/dynamic-parameters-test1.ps1 index 4f7b2fa..817ffdc 100644 --- a/common/code-upgrade-samples/az/dynamic-parameters-test1.ps1 +++ b/common/code-upgrade-samples/az/dynamic-parameters-test1.ps1 @@ -3,5 +3,5 @@ New-AzResourceGroupDeployment -ResourceGroupName "ContosoEngineering" ` -TemplateFile "D:\Azure\Templates\EngineeringSite.json" ` -TemplateParameterFile "D:\Azure\Templates\EngSiteParms.json" ` - - "test1" ` - - "test2" + -DynamicUserParam1 "test1" ` + -DynamicUserParam2 "test2" diff --git a/powershell-module/Az.Tools.Migration/Az.Tools.Migration.psd1 b/powershell-module/Az.Tools.Migration/Az.Tools.Migration.psd1 index d71a7a0..7fa41f1 100644 --- a/powershell-module/Az.Tools.Migration/Az.Tools.Migration.psd1 +++ b/powershell-module/Az.Tools.Migration/Az.Tools.Migration.psd1 @@ -3,7 +3,7 @@ RootModule = 'Az.Tools.Migration.psm1' # Version number of this module. - ModuleVersion = '1.1.0' + ModuleVersion = '1.1.1' # Supported PSEditions CompatiblePSEditions = 'Core', 'Desktop' @@ -108,11 +108,7 @@ # IconUri = '' # ReleaseNotes of this module - ReleaseNotes = '* Upgrade Az version to 5.6.0 - * Fixed a bug where New-AzUpgradeModulePlan throws errors when analyzing hashtable code (issue #73). - * Updated scanning results for Az cmdlets that implement dynamic parameters to use clearer warnings. - * Updated Get-AzUpgradeCmdletSpec to improve performance. - * Updated quickstart guide to remove outdated guidance on splatted parameter detection.' + ReleaseNotes = '* Fixed a bug in Invoke-AzUpgradeModulePlan where dynamic parameters are incorrectly updated (issue #81).' } } diff --git a/powershell-module/Az.Tools.Migration/Functions/Private/Invoke-ModuleUpgradeStep.ps1 b/powershell-module/Az.Tools.Migration/Functions/Private/Invoke-ModuleUpgradeStep.ps1 index 960bc4f..f4a28f7 100644 --- a/powershell-module/Az.Tools.Migration/Functions/Private/Invoke-ModuleUpgradeStep.ps1 +++ b/powershell-module/Az.Tools.Migration/Functions/Private/Invoke-ModuleUpgradeStep.ps1 @@ -50,22 +50,30 @@ function Invoke-ModuleUpgradeStep -StartOffset $Step.SourceCommand.StartOffset -EndOffset $Step.SourceCommand.EndOffset # replacement code - $null = $FileContent.Remove($Step.SourceCommand.StartOffset, ($Step.SourceCommand.EndOffset - $Step.SourceCommand.StartOffset)); - $null = $FileContent.Insert($Step.SourceCommand.StartOffset, $Step.Replacement); + $null = $FileContent.Remove($Step.SourceCommand.StartOffset, ($Step.SourceCommand.EndOffset - $Step.SourceCommand.StartOffset)) + $null = $FileContent.Insert($Step.SourceCommand.StartOffset, $Step.Replacement) } "CmdletParameter" { - Write-Verbose -Message ("[{0}] Updating CmdletParameter {1} to {2}." ` - -f $Step.Location, $Step.Original, $Step.Replacement) + if ([System.String]::IsNullOrWhiteSpace($Step.Replacement) -eq $false) + { + Write-Verbose -Message ("[{0}] Updating CmdletParameter {1} to {2}." ` + -f $Step.Location, $Step.Original, $Step.Replacement) - # safety check - # ensure that the file offsets are an exact match. - Confirm-StringBuilderSubstring -FileContent $FileContent -Substring $Step.Original ` - -StartOffset $Step.SourceCommandParameter.StartOffset -EndOffset $Step.SourceCommandParameter.EndOffset + # safety check + # ensure that the file offsets are an exact match. + Confirm-StringBuilderSubstring -FileContent $FileContent -Substring $Step.Original ` + -StartOffset $Step.SourceCommandParameter.StartOffset -EndOffset $Step.SourceCommandParameter.EndOffset - # replacement code - $null = $FileContent.Remove($Step.SourceCommandParameter.StartOffset, ($Step.SourceCommandParameter.EndOffset - $Step.SourceCommandParameter.StartOffset)); - $null = $FileContent.Insert($Step.SourceCommandParameter.StartOffset, $Step.Replacement); + # replacement code + $null = $FileContent.Remove($Step.SourceCommandParameter.StartOffset, ($Step.SourceCommandParameter.EndOffset - $Step.SourceCommandParameter.StartOffset)) + $null = $FileContent.Insert($Step.SourceCommandParameter.StartOffset, $Step.Replacement) + } + else + { + Write-Verbose -Message ("[{0}] Skipping CmdletParameter {1}, it has no automated replacement." ` + -f $Step.Location, $Step.Original) + } } default { diff --git a/powershell-module/ChangeLog.md b/powershell-module/ChangeLog.md index 99cbc05..f0ae178 100644 --- a/powershell-module/ChangeLog.md +++ b/powershell-module/ChangeLog.md @@ -19,6 +19,9 @@ --> ## Upcoming Release +## 1.1.1 +* Fixed a bug in Invoke-AzUpgradeModulePlan where dynamic parameters are incorrectly updated (issue #81). + ## 1.1.0 * Upgrade Az version to 5.6.0 * Fixed a bug where New-AzUpgradeModulePlan throws errors when analyzing hashtable code (issue #73).