Azure : Powershell Script to fix IP addresses of a group of Virtual Machine

Hi all,

In my previous post, I posted a script that allow you to fix an Azure virtual machine IP address. But what will you do if you created or have 20 VMs with dynamic IP addresses ? What if you want to set a static IP address for 50 VMs? No worry, I wrote this script that will let you fix IP addresses on a bunch of Azure virtual machines. 

How it works

  • The script use a CSV file that contains the needed information to fix IP addresses for a group of virtual machine. You must provide a valid CSV file as an input. The file is 4 columns separated CSV file : the columns are Name, ServiceName, IpAddress and VirtualNetworkName. You can download and edit this sample CSV file HERE
  • Filling a CSV file can be time consuming and error prone (Specially if we are dealing with tens of VMs). So i added a sweet feature to the script that connect to your Azure subscription and generate a file containing all the VM’s information. you will just edit this CSV file by removing the extra VMs and choosing the right IP addresses


  • Download and install  the Azure Powershell modules HERE
  • Copy the script to a local location (Example : C:\Scripts)
  • Run an elevated Powershell window
  • change the powershell script execution policy to unrestricted (Set-ExecutionPolicy Unrestricted)


  • Browse the folder where the script resides and run it using the following syntax
    • If you want to generate a csv file, you will only provide the Azure Subscription Name as an input, a csv file named AzureVMlist.csv will be generated on the same script folder  

.\SetAzureVMStaticIPfromCSV.ps1 -SubscriptionName ‘SubscriptionName

    • If your CSV file is already created, use the following syntax to run the script

.\SetAzureVMStaticIPfromCSV.ps1 -SubscriptionName ‘SubscriptionName‘ -csvpath csvfilepath


  1. To Generate a CSV file
    .\SetAzureVMStaticIPfromCSV.ps1 -SubscriptionName ‘BuildWindows – SAMIR FARHAT’
  2. Using a CSV file
    .\SetAzureVMStaticIPfromCSV.ps1 -SubscriptionName ‘BuildWindows – SAMIR FARHAT’ -csvpath .\Azurevmlist.csv


  • This script will only work on VMs with one single NIC. I will soon post another script that support fixing IP addresses for VMs with multiple NICs
  • Azure will restart your machines to apply the modifications, so be aware of it

You can download the script here

2 thoughts on “Azure : Powershell Script to fix IP addresses of a group of Virtual Machine

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s