Use PowerShell to Create a Reserved Virtual IP Address (VIP) in Azure

By default, the VM's that you create in Azure will have a dynamic virtual IP address (VIP). Based on this article on Azure, you could simply create a DNS CNAME record for your custom domain and point it to the DNS name that you chose during the creation of your azure VM which should prevent any problems if the virtual IP address happens to change.

Maybe you want a reserved virtual IP address for your Azure instance though? There's a limited number of reserved virtual IP addresses per subscription so make sure you use them sparingly if you do indeed want to create and use reserved virtual IP addresses.

1New-AzureReservedIP ReservedIPName 'mikefrobbinsIP' Location 'South Central US'

azure-ip1a.jpg

The Get-AzureReservedIP PowerShell cmdlet can be used to see the actual IP address once the reservation has been created. For security reasons, I've blurred out the actual IP address that was created in the following example:

1Get-AzureReservedIP ReservedIPName 'mikefrobbinsIP'

azure-ip2a.jpg

The same cmdlet can be used to determine how many virtual IP addresses you've already reserved in Azure:

1(Get-AzureReservedIP).count

azure-ip3a.jpg

One of the catches is that you can't assign a reserved virtual IP address to a VM that already exists in Azure. Based on what I've read this is something that they're working on so it is subject to change.

The Remove-AzureReservedIP cmdlet is used to remove a reserved virtual IP address. If it's currently in use (associated with an Azure cloud service), the removal will fail:

1Get-AzureReservedIP -ReservedIPName mikefrobbinsIP | Remove-AzureReservedIP

azure-ip4a.jpg

1Remove-AzureReservedIP : BadRequest: The Reserved IP mikefrobbinsIP is currently in use by Deployment
2mikefrobbins-test belonging to HostedService mikefrobbins-test.
3At line:1 char:54
4+ … ureReservedIP -ReservedIPName mikefrobbinsIP | Remove-AzureReservedIP
5+ ~~~~~~~~~~~~~~~~~~~~~~
6+ CategoryInfo : CloseError: (:) [Remove-AzureReservedIP], CloudException
7+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.RemoveAzureReservedIPCmdlet

Based on my testing, even if you delete the VM and the Cloud Service that the reserved virtual IP address is associated with, the IP will remain reserved and associated with your Azure subscription.

µ