SALES: 1-800-867-1380

Move a VM or Role Instance to a Different Subnet

Updated: November 11, 2014

You can use PowerShell to move your VMs from one subnet to another in the same virtual network. Role instances can be moved by editing the CSCFG, rather than using PowerShell.

Why move VMs to another subnet? Subnet migration is useful when the older subnet is too small and cannot be expanded due to existing running VMs in that subnet. In that case, you can create a new, larger subnet and migrate the VMs to the new subnet, then after migration is complete, you can delete the empty old subnet.

To move a VM, run the PowerShell cmdlet, using the example below as a template. In the example below, we are moving TestVM from its present subnet, to Subnet-2. Be sure to edit the example to reflect your environment. Note that whenever you run the Update-AzureVM cmdlet as part of a procedure, it will restart your VM as part of the update process.

Get-AzureVM –ServiceName TestVMCloud –Name TestVM | Set-AzureSubnet –SubnetNames Subnet-2 | Update-AzureVM

If you specified a static DIP for your VM, you’ll have to clear that setting before you can move the VM to a new subnet. In that case, use the following:

Get-AzureVM -ServiceName TestVMCloud -Name TestVM | Remove-AzureStaticVNetIP | Update-AzureVM
Get-AzureVM -ServiceName TestVMCloud -Name TestVM | Set-AzureSubnet -SubnetNames Subnet-2 | Update-AzureVM

To move a role instance, edit the CSCFG file. In the example below, we are moving “Role0” in virtual network VNETName from its present subnet to Subnet-2. Because the role instance was already deployed, you’ll just change the Subnet name = Subnet-2. Be sure to edit the example to reflect your environment.

<NetworkConfiguration>
    <VirtualNetworkSite name="VNETName" />
    <AddressAssignments>
       <InstanceAddress roleName="Role0">
            <Subnets><Subnet name="Subnet-2" /></Subnets>
       </InstanceAddress>
    </AddressAssignments>
</NetworkConfiguration>

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft