Today we needed to set a static IP on a VM we had in Azure, because Azure uses its own DHCP server so applying a reservation isn’t an option here.
So to do so we need to break out some Powershell!
First off you need Azure powershell – download and install from here: http://go.microsoft.com/?linkid=9828653&clcid=0x409
Next you need to connect to your azure platform, this is lots easier than I first thought, just type “Add-AzureAccount” and you will be prompted for your login – enter your details and you are away.
You need to find out what service name your VM sits in (basically which cloud) so you can either pop on to the portal and click on Clouds and ensure the VM you want is in there or in the powershell window try:
Get-AzureVM – which will pop out a list of service name and VM names. Now we just need to set a variable to work with – grabbing the info from the two bits we just got.
$staticVM = Get-AzureVM –ServiceName <cloudname> -Name <nameofVM>
Next let’s just test the ip your wanting to set is free, you will need to grab the name of the network you have setup (From networks in the portal), then:
Test-AzureStaticVNetIP –VnetName <virtualnetworkname> -IPAddress <IPyouwishtoset>
All being well you should get a message back to say it’s available, something like this:
If all is well lets set the IP:
Set-AzureStaticVNetIP -VM $staticVM -IPAddress <IPyouwishtoset>| Update-AzureVM
*NOTE* This will restart the VM! I found that out the hard way.
Hope it helps.