Skip to content

Commit e965f36

Browse files
authored
Fixed bug in Invoke-AzUpgradeModulePlan dynamic parameter handling (#82)
* Bug fix for dynamic parameter detection * Bumped version
1 parent 0b3354a commit e965f36

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

common/code-upgrade-samples/az/dynamic-parameters-test1.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
New-AzResourceGroupDeployment -ResourceGroupName "ContosoEngineering" `
44
-TemplateFile "D:\Azure\Templates\EngineeringSite.json" `
55
-TemplateParameterFile "D:\Azure\Templates\EngSiteParms.json" `
6-
- "test1" `
7-
- "test2"
6+
-DynamicUserParam1 "test1" `
7+
-DynamicUserParam2 "test2"

powershell-module/Az.Tools.Migration/Az.Tools.Migration.psd1

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RootModule = 'Az.Tools.Migration.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '1.1.0'
6+
ModuleVersion = '1.1.1'
77

88
# Supported PSEditions
99
CompatiblePSEditions = 'Core', 'Desktop'
@@ -108,11 +108,7 @@
108108
# IconUri = ''
109109

110110
# ReleaseNotes of this module
111-
ReleaseNotes = '* Upgrade Az version to 5.6.0
112-
* Fixed a bug where New-AzUpgradeModulePlan throws errors when analyzing hashtable code (issue #73).
113-
* Updated scanning results for Az cmdlets that implement dynamic parameters to use clearer warnings.
114-
* Updated Get-AzUpgradeCmdletSpec to improve performance.
115-
* Updated quickstart guide to remove outdated guidance on splatted parameter detection.'
111+
ReleaseNotes = '* Fixed a bug in Invoke-AzUpgradeModulePlan where dynamic parameters are incorrectly updated (issue #81).'
116112
}
117113
}
118114

powershell-module/Az.Tools.Migration/Functions/Private/Invoke-ModuleUpgradeStep.ps1

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,30 @@ function Invoke-ModuleUpgradeStep
5050
-StartOffset $Step.SourceCommand.StartOffset -EndOffset $Step.SourceCommand.EndOffset
5151

5252
# replacement code
53-
$null = $FileContent.Remove($Step.SourceCommand.StartOffset, ($Step.SourceCommand.EndOffset - $Step.SourceCommand.StartOffset));
54-
$null = $FileContent.Insert($Step.SourceCommand.StartOffset, $Step.Replacement);
53+
$null = $FileContent.Remove($Step.SourceCommand.StartOffset, ($Step.SourceCommand.EndOffset - $Step.SourceCommand.StartOffset))
54+
$null = $FileContent.Insert($Step.SourceCommand.StartOffset, $Step.Replacement)
5555
}
5656
"CmdletParameter"
5757
{
58-
Write-Verbose -Message ("[{0}] Updating CmdletParameter {1} to {2}." `
59-
-f $Step.Location, $Step.Original, $Step.Replacement)
58+
if ([System.String]::IsNullOrWhiteSpace($Step.Replacement) -eq $false)
59+
{
60+
Write-Verbose -Message ("[{0}] Updating CmdletParameter {1} to {2}." `
61+
-f $Step.Location, $Step.Original, $Step.Replacement)
6062

61-
# safety check
62-
# ensure that the file offsets are an exact match.
63-
Confirm-StringBuilderSubstring -FileContent $FileContent -Substring $Step.Original `
64-
-StartOffset $Step.SourceCommandParameter.StartOffset -EndOffset $Step.SourceCommandParameter.EndOffset
63+
# safety check
64+
# ensure that the file offsets are an exact match.
65+
Confirm-StringBuilderSubstring -FileContent $FileContent -Substring $Step.Original `
66+
-StartOffset $Step.SourceCommandParameter.StartOffset -EndOffset $Step.SourceCommandParameter.EndOffset
6567

66-
# replacement code
67-
$null = $FileContent.Remove($Step.SourceCommandParameter.StartOffset, ($Step.SourceCommandParameter.EndOffset - $Step.SourceCommandParameter.StartOffset));
68-
$null = $FileContent.Insert($Step.SourceCommandParameter.StartOffset, $Step.Replacement);
68+
# replacement code
69+
$null = $FileContent.Remove($Step.SourceCommandParameter.StartOffset, ($Step.SourceCommandParameter.EndOffset - $Step.SourceCommandParameter.StartOffset))
70+
$null = $FileContent.Insert($Step.SourceCommandParameter.StartOffset, $Step.Replacement)
71+
}
72+
else
73+
{
74+
Write-Verbose -Message ("[{0}] Skipping CmdletParameter {1}, it has no automated replacement." `
75+
-f $Step.Location, $Step.Original)
76+
}
6977
}
7078
default
7179
{

powershell-module/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
-->
2020
## Upcoming Release
2121

22+
## 1.1.1
23+
* Fixed a bug in Invoke-AzUpgradeModulePlan where dynamic parameters are incorrectly updated (issue #81).
24+
2225
## 1.1.0
2326
* Upgrade Az version to 5.6.0
2427
* Fixed a bug where New-AzUpgradeModulePlan throws errors when analyzing hashtable code (issue #73).

0 commit comments

Comments
 (0)