How to Change an Azure VM’s Subnet

Oops…put my Windows 8.1 Azure VM on my Azure virtual network, on the server subnet and with a static IP address.  Here’s how to correct with a bit of Azure PowerShell.

Parameters:

  • Client name and Azure Cloud Service name – W81.
  • Client subnet name – ClientVNet

Procedure

  • Connect to Azure and enter credentials when prompted.

Add-AzureAccount

  • Select your Azure subscription.

Select-AzureSubscription -SubscriptionName “Azure Pass”

  • Shutdown the VM ensuring the IP addresses are de-allocated (the –Force bit).

Stop-AzureVM -ServiceName W81 -Name W81 -Force

  • Remove the static IP allocated to the VM.

Get-AzureVM -ServiceName W81 -Name W81 | Remove-AzureStaticVNetIP | Update-AzureVM

  • Allocate the client subnet.

Get-AzureVM -ServiceName W81 -Name W81 | Set-AzureSubnet -SubnetNames ClientVNet | Update-AzureVM

  • Set a new static IP on the client subnet.

Get-AzureVM -ServiceName W81 -Name W81 | Set-AzureStaticVNetIP -IPAddress 10.1.1.81 | Update-AzureVM