diff --git a/src/Migrate/custom/Start-AzMigrateTestMigration.ps1 b/src/Migrate/custom/Start-AzMigrateTestMigration.ps1 index 70551e3835a7..4874e015362e 100644 --- a/src/Migrate/custom/Start-AzMigrateTestMigration.ps1 +++ b/src/Migrate/custom/Start-AzMigrateTestMigration.ps1 @@ -117,7 +117,6 @@ function Start-AzMigrateTestMigration { $FabricName = $MachineIdArray[10] $ProtectionContainerName = $MachineIdArray[12] $MachineName = $MachineIdArray[14] - $null = $PSBoundParameters.Add("ResourceGroupName", $ResourceGroupName) $null = $PSBoundParameters.Add("ResourceName", $VaultName) @@ -126,6 +125,44 @@ function Start-AzMigrateTestMigration { $null = $PSBoundParameters.Add("ProtectionContainerName", $ProtectionContainerName) $ReplicationMigrationItem = Az.Migrate.internal\Get-AzMigrateReplicationMigrationItem @PSBoundParameters + $AvSetId = $ReplicationMigrationItem.ProviderSpecificDetail.TargetAvailabilitySetId + if ($AvSetId) + { + Import-module -Name Az.Compute + Import-module -Name Az.Network + $AvSetName = $AvSetId.Split("/")[-1]; + $AvSetRg = $AvSetId.Split("/")[-5]; + $AvSet = Get-AzAvailabilitySet -ResourceGroupName $AvSetRg -Name $AvSetName -ErrorVariable notPresent -ErrorAction SilentlyContinue + if (!$AvSet) + { + throw "Availability Set '$($AvSetId)' does not exist." + } + if ($AvSet.VirtualMachineReferences -And ($AvSet.VirtualMachineReferences.Count -gt 0)) + { + $VminAvSet = $AvSet.VirtualMachinesReferences[0].Id + if ($VminAvSet) + { + $VmNameinAvSet = $VminAvSet.Split("/")[-1] + $VM = Get-AzVM -ResourceGroupName $AvSetRg -Name $VmNameinAvSet -ErrorVariable notPresent -ErrorAction SilentlyContinue + if ($VM) + { + $NicId = $VM.NetworkProfile.NetworkInterfaces[0].Id + $Nic = Get-Aznetworkinterface -resourceid $NicId -ErrorVariable notPresent -ErrorAction SilentlyContinue + if($Nic -And ($Nic.IpConfigurations) -And ($Nic.IpConfigurations[0].Subnet) -And ($Nic.IpConfigurations[0].Subnet.Id)) + { + $Subnet = $Nic.IpConfigurations[0].Subnet.Id.Split("/") + $VnetID = "/$($Subnet[1])/$($Subnet[2])/$($Subnet[3])/$($Subnet[4])/$($Subnet[5])/$($Subnet[6])/$($Subnet[7])/$($Subnet[8])" + } + + if ($TestNetworkID -ne $VnetID) + { + throw "Virtual Machines in the availability set '$AvSetName' can only be connected to virtual network '$VnetID'. Change the virtual network selected for the test or update the availability set for the machines, and retry the operation." + } + } + } + } + } + if ($ReplicationMigrationItem -and ($ReplicationMigrationItem.ProviderSpecificDetail.InstanceType -eq 'VMwarecbt') -and ($ReplicationMigrationItem.AllowedOperation -contains 'TestMigrate' )) { $ProviderSpecificDetailInput = [Microsoft.Azure.PowerShell.Cmdlets.Migrate.Models.Api20210210.VMwareCbtTestMigrateInput]::new() $ProviderSpecificDetailInput.InstanceType = 'VMwareCbt'