Hello ,
Thanks for reaching out to Microsoft Q and A forum ,
Your Current Cloud Solution
Single Active VM + Stopped VM (Manual Failover) Downtime is acceptable --> This is your 100% manual current use case
Recommended Solution :
Standard load balancer, Attach the public Ip's to the Lb + VMSS (scale set) with 1 Always-Running VM --> If you want some automation with similar downtime might be just a few $ more monthly (6$-8$)
But if you want to stick on to current solution only , Here is a PowerShell script which can help you .
Variables
$primaryVMName = "PrimaryVM"
$standbyVMName = "StandbyVM"
$resourceGroupName = "YourResourceGroup"
$location = "YourAzureRegion"
Authenticate to Azure
Connect-AzAccount
Stop the primary VM
Stop-AzVM -Name $primaryVMName -ResourceGroupName $resourceGroupName -Force
Get the NIC of the primary VM
$primaryVM = Get-AzVM -Name $primaryVMName -ResourceGroupName $resourceGroupName
$primaryNIC = Get-AzNetworkInterface -Name $primaryVM.NetworkProfile.NetworkInterfaces[0].Id.Split('/')[-1] -ResourceGroupName $resourceGroupName
Get the NIC of the standby VM
$standbyVM = Get-AzVM -Name $standbyVMName -ResourceGroupName $resourceGroupName
$standbyNIC = Get-AzNetworkInterface -Name $standbyVM.NetworkProfile.NetworkInterfaces[0].Id.Split('/')[-1] -ResourceGroupName $resourceGroupName
Loop through each IP configuration in the primary NIC (excluding the primary IP)
foreach ($ipConfig in $primaryNIC.IpConfigurations) {
if ($ipConfig.Primary -eq $false) {
# Remove IP configuration from primary NIC
$primaryNIC.IpConfigurations.Remove($ipConfig)
# Add IP configuration to standby NIC
$standbyNIC.IpConfigurations.Add($ipConfig)
}
}
Update both NICs
Set-AzNetworkInterface -NetworkInterface $primaryNIC
Set-AzNetworkInterface -NetworkInterface $standbyNIC
Start the standby VM
Start-AzVM -Name $standbyVMName -ResourceGroupName $resourceGroupName
Please don't forget to accept the answer if this was helpful .
Thanks,
Pradeep