Today I needed to associate a public IP address to an existing Azure virtual machine. The Microsoft Docs website has an article that describes how to do it. But somehow the Powershell example didn’t work.
In this short post I will provide you with a Powershell snippet that will actually work.
The Powershell example
The example below creates a public IP address in Azure and associates it to an existing Network Interface.
- You can either use the Azure Cloud Shell or use a local installation of Powershell to execute the code snippet. If you are using Powershell locally, make sure you have the Azure Powershell module installed.
- If you have multiple subscriptions, use the
Select-AzSubscriptioncommand first to select the right subscription.
In the example I create a public IP of Sku “Basic”, allocation method “Dynamic” and in region “West Europe”. You might need to change these values to your specific needs. Consult the docs on the New-AzPublicIpAddress cmdlet here.
If Powershell is your tool of choice, and you need add a public IP address to an existing network interface, this code snippet will work for you.
comments powered by Disqus