How to Assign a Private Static IP to an Azure VM

In most cases, you won’t need to specify a static internal IP address (DIP) for your virtual machine. VMs in a virtual network will automatically receive an internal IP address from a range that you specify. But in certain cases, specifying a static IP address for a particular VM makes sense. For example, if your VM is going to run DNS or will be a domain controller. Or, if you have a VM that you plan to stop/deprovision at some point, but want retain the DIP for the VM when you provision it again. A static DIP stays with the VM even through a stop/deprovision state. You can specify a static DIP by using PowerShell at the time you create the VM, or you can update an existing VM.

Here is an example script I use in my environment.

  • $IPaddress: You need to specify the static IP address to assign to your VM
  • $VNETName: You need to specify the Name of the virtual Network that the Static IP address belongs to
  • $VMName: The name of the VM to update
  • $ServiceName: The name of the cloud service to which the VM belongs

If you get the following error:

Just use the command Add-AzureAccount to refresh your Azure credential.


After this command a window will popup asking for your mailaddress to logon to Microsoft Azure. (Sorry for the dutch screenshots)

Add-AzureAccount - mailaddress

Then enter your full credentials and hit logon.

Add-AzureAccount - Full Credentials

That’s it. If run the script and it is successful, it will return this:

(Picture lost)


Sources: and a TechNet wiki article.