Skip to content

Az.Migrate - Fix ErrorAction duplication error #27811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function Get-AzMigrateLocalServerReplication {
if ($parameterSet -eq 'GetBySDSID') {
$machineIdArray = $DiscoveredMachineId.Split("/")
if ($machineIdArray.Length -lt 11) {
throw "Invalid machine ID '$DiscoveredMachineId'"
throw "Invalid machine ARM ID '$DiscoveredMachineId'"
}
$siteType = $machineIdArray[7]
$siteName = $machineIdArray[8]
Expand Down
31 changes: 29 additions & 2 deletions src/Migrate/Migrate.Autorest/custom/Helper/CommonHelper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,35 @@ function InvokeAzMigrateGetCommandWithRetries {
)

process {
# Filter out ErrorAction and ErrorVariable from the parameters
$params = @{}
foreach ($key in $Parameters.Keys) {
if ($key -ne "ErrorAction" -and $key -ne "ErrorVariable") {
$params[$key] = $Parameters[$key]
}
}

# Extract user-specified ErrorAction and ErrorVariable or defaults
# but do not include them in $params
if ($Parameters.ContainsKey("ErrorVariable")) {
$errorVariable = $Parameters["ErrorVariable"]
}
else
{
$errorVariable = "notPresent"
}

if ($Parameters.ContainsKey("ErrorAction")) {
$errorAction = $Parameters["ErrorAction"]
}
else
{
$errorAction = "Continue"
}

for ($i = 0; $i -le $MaxRetryCount; $i++) {
try {
$result = & $CommandName @Parameters -ErrorVariable notPresent -ErrorAction SilentlyContinue
$result = & $CommandName @params -ErrorVariable $errorVariable -ErrorAction $errorAction

if ($null -eq $result) {
throw $ErrorMessage
Expand All @@ -223,14 +249,15 @@ function InvokeAzMigrateGetCommandWithRetries {
Start-Sleep -Seconds $RetryDelayInSeconds
}
else {
throw $ErrorMessage
throw "Get command failed after $MaxRetryCount retries. Error: $($_.Exception)"
}
}
}

return $result
}
}

function ValidateReplication {
[Microsoft.Azure.PowerShell.Cmdlets.Migrate.DoNotExportAttribute()]
param (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,22 @@ function New-AzMigrateLocalServerReplication {
$null = $PSBoundParameters.Remove('Confirm')

$MachineIdArray = $MachineId.Split("/")
if ($MachineIdArray.Length -lt 11) {
throw "Invalid machine ARM ID '$MachineId'"
}
$SiteType = $MachineIdArray[7]
$SiteName = $MachineIdArray[8]
$ResourceGroupName = $MachineIdArray[4]
$MachineName = $MachineIdArray[10]

if (($SiteType -ne $SiteTypes.HyperVSites) -and ($SiteType -ne $SiteTypes.VMwareSites)) {
throw "Site type is not supported. Site type '$SiteType'. Check MachineId provided."
}

# Get the source site and the discovered machine
$null = $PSBoundParameters.Add("ResourceGroupName", $ResourceGroupName)
$null = $PSBoundParameters.Add("SiteName", $SiteName)
$null = $PSBoundParameters.Add("MachineName", $MachineName)

if (($SiteType -ne $SiteTypes.HyperVSites) -and ($SiteType -ne $SiteTypes.VMwareSites)) {
throw "Site type is not supported. Site type '$SiteType'. Check MachineId provided."
}

if ($SiteType -eq $SiteTypes.HyperVSites) {
$instanceType = $AzLocalInstanceTypes.HyperVToAzLocal
Expand Down
1 change: 1 addition & 0 deletions src/Migrate/Migrate/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->
## Upcoming Release
* Implemented the Get-AzMigrateServerMigrationStatus cmdlet to retrieve the replication status of servers in Azure Migrate.
* Fixed bugs in `New-AzMigrateLocalServerReplication` that caused HyperVSite or VMwareSite not found.

## Version 2.7.1

Expand Down