Skip to content

Commit 2dc5ce2

Browse files
minhsuanleeSam Lee
and
Sam Lee
authored
Az.Migrate - Fix ErrorAction duplication error (#27811)
Co-authored-by: Sam Lee <samlee3@microsoft.com>
1 parent 5c55e01 commit 2dc5ce2

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

src/Migrate/Migrate.Autorest/custom/Get-AzMigrateLocalServerReplication.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function Get-AzMigrateLocalServerReplication {
147147
if ($parameterSet -eq 'GetBySDSID') {
148148
$machineIdArray = $DiscoveredMachineId.Split("/")
149149
if ($machineIdArray.Length -lt 11) {
150-
throw "Invalid machine ID '$DiscoveredMachineId'"
150+
throw "Invalid machine ARM ID '$DiscoveredMachineId'"
151151
}
152152
$siteType = $machineIdArray[7]
153153
$siteName = $machineIdArray[8]

src/Migrate/Migrate.Autorest/custom/Helper/CommonHelper.ps1

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,35 @@ function InvokeAzMigrateGetCommandWithRetries {
208208
)
209209

210210
process {
211+
# Filter out ErrorAction and ErrorVariable from the parameters
212+
$params = @{}
213+
foreach ($key in $Parameters.Keys) {
214+
if ($key -ne "ErrorAction" -and $key -ne "ErrorVariable") {
215+
$params[$key] = $Parameters[$key]
216+
}
217+
}
218+
219+
# Extract user-specified ErrorAction and ErrorVariable or defaults
220+
# but do not include them in $params
221+
if ($Parameters.ContainsKey("ErrorVariable")) {
222+
$errorVariable = $Parameters["ErrorVariable"]
223+
}
224+
else
225+
{
226+
$errorVariable = "notPresent"
227+
}
228+
229+
if ($Parameters.ContainsKey("ErrorAction")) {
230+
$errorAction = $Parameters["ErrorAction"]
231+
}
232+
else
233+
{
234+
$errorAction = "Continue"
235+
}
236+
211237
for ($i = 0; $i -le $MaxRetryCount; $i++) {
212238
try {
213-
$result = & $CommandName @Parameters -ErrorVariable notPresent -ErrorAction SilentlyContinue
239+
$result = & $CommandName @params -ErrorVariable $errorVariable -ErrorAction $errorAction
214240

215241
if ($null -eq $result) {
216242
throw $ErrorMessage
@@ -223,14 +249,15 @@ function InvokeAzMigrateGetCommandWithRetries {
223249
Start-Sleep -Seconds $RetryDelayInSeconds
224250
}
225251
else {
226-
throw $ErrorMessage
252+
throw "Get command failed after $MaxRetryCount retries. Error: $($_.Exception)"
227253
}
228254
}
229255
}
230256

231257
return $result
232258
}
233259
}
260+
234261
function ValidateReplication {
235262
[Microsoft.Azure.PowerShell.Cmdlets.Migrate.DoNotExportAttribute()]
236263
param (

src/Migrate/Migrate.Autorest/custom/New-AzMigrateLocalServerReplication.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,22 @@ function New-AzMigrateLocalServerReplication {
188188
$null = $PSBoundParameters.Remove('Confirm')
189189

190190
$MachineIdArray = $MachineId.Split("/")
191+
if ($MachineIdArray.Length -lt 11) {
192+
throw "Invalid machine ARM ID '$MachineId'"
193+
}
191194
$SiteType = $MachineIdArray[7]
192195
$SiteName = $MachineIdArray[8]
193196
$ResourceGroupName = $MachineIdArray[4]
194197
$MachineName = $MachineIdArray[10]
195-
196-
if (($SiteType -ne $SiteTypes.HyperVSites) -and ($SiteType -ne $SiteTypes.VMwareSites)) {
197-
throw "Site type is not supported. Site type '$SiteType'. Check MachineId provided."
198-
}
199198

200199
# Get the source site and the discovered machine
201200
$null = $PSBoundParameters.Add("ResourceGroupName", $ResourceGroupName)
202201
$null = $PSBoundParameters.Add("SiteName", $SiteName)
203202
$null = $PSBoundParameters.Add("MachineName", $MachineName)
203+
204+
if (($SiteType -ne $SiteTypes.HyperVSites) -and ($SiteType -ne $SiteTypes.VMwareSites)) {
205+
throw "Site type is not supported. Site type '$SiteType'. Check MachineId provided."
206+
}
204207

205208
if ($SiteType -eq $SiteTypes.HyperVSites) {
206209
$instanceType = $AzLocalInstanceTypes.HyperVToAzLocal

src/Migrate/Migrate/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020
## Upcoming Release
2121
* Implemented the Get-AzMigrateServerMigrationStatus cmdlet to retrieve the replication status of servers in Azure Migrate.
22+
* Fixed bugs in `New-AzMigrateLocalServerReplication` that caused HyperVSite or VMwareSite not found.
2223

2324
## Version 2.7.1
2425

0 commit comments

Comments
 (0)