Recently we had the need to change the public IP of some Azure VMs to be static instead of dynamic to prevent them from changing when the VM is shut down or deallocated. It was interesting to see that it is possible to reserve the same IP the VMs are currently using which prevent us from having to update references to those IPs. And also it is possible to do so without any downtime as the VM doesn't need to be restarted. PowerShell is the only way available at the time being to get this done.

How to do it

1. The steps to reserve the VM’s IP are as follows:

Step 1: Get the settings required by PowerShell to connect to the Azure subscription. 

Step 2: With your favourite browser, navigate to, log in and select the subscription where the target VM is. 

Step 3: Run the following PowerShell command which will download a file with the settings required by PowerShell to connect to the same subscription.          


Step 4: Save the previously downloaded file in a safe location.


Connect PowerShell to the target Azure subscription

2. Run the following two PowerShell statements after setting the path to the Publishing Settings file (downloaded in the previous step) and the Azure SubscriptionName.

Import-AzurePublishSettingsFile "<Path to Publish Settings file>"
Select-AzureSubscription -SubscriptionName "<Subscription Name>"

3. [Optional] We can check the currently reserved IPs:


We can also save this information to a file for tracking purposes.

Get-AzureReservedIP >> "C:\ReservedIPs.old.details.txt"

4. Reserve the IP that is currently assigned to the VM:

Run the following command after setting the right values to its parameters.

New-AzureReservedIP –ReservedIPName <IP Name> –Location "<Region>" -ServiceName <Cloud Service Name>

ReservedIPName: Name to be used to identify the reserved IP. • Location: Name of the Azure Region where the VM is and where the IP will be reserved.
ServiceName: Name of the Azure Cloud Service associated to the VM.

5. [Optional] We can check again the currently reserved IPs where the new IP should be:


We can also save this information to a file for tracking purposes.

Get-AzureReservedIP >> "C:\"

How to double-check the VM has a reserved IP

The above procedure not only reserves the IP but also associates it to the VM. We can confirm it with the following steps:
Step 1: With your favourite browser navigate to the new Azure Management Portal
Step 2: Select the subscription where the target VM is.
Step 3: Go to “Virtual Machines (classic)”.
Step 4: Select (click on) the target VM which IP has just been reserved.
Step 5: On the Settings panel click on “IP addresses”.
Step 6: On the “IP addresses” panel we can check whether the IP is reserved and associated to the VM:

Additional information

Author bio

Benjamin Moles
Benjamin Moles
Sitecore Developer
My goal is to return happiness to clients' faces by getting their issues and questions solved. As a Technical Service Manager I provide the required resources to support clients' applications and infrastructure. I also enjoy playing with remote-controlled helicopters.


comments powered by Disqus

Related Articles

Sign up to our ClearThought newsletter

Get inspired and learn something new by subscribing to our FREE newsletter. It’s full of ClearPeople's thought-leadership whitepapers, blogs, events, and much more. We promise to not use your email for spam.

Closing this message and/or accessing our website tells us you are happy to receive all cookies on the ClearPeople website.
However, if you would like to, you can change your cookies settings at any time.