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.

New-AzureReservedIPReservedIPName '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:

Get-AzureReservedIPReservedIPName 'mikefrobbinsIP'

azure-ip2a.jpg

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

(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:

Get-AzureReservedIP -ReservedIPName mikefrobbinsIP | Remove-AzureReservedIP

azure-ip4a.jpg

Remove-AzureReservedIP : BadRequest: The Reserved IP mikefrobbinsIP is currently in use by Deployment
mikefrobbins-test belonging to HostedService mikefrobbins-test.
At line:1 char:54
+ … ureReservedIP -ReservedIPName mikefrobbinsIP | Remove-AzureReservedIP
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Remove-AzureReservedIP], CloudException
+ 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.

µ