Disassociate public IP from Azure Firewall with Powershell

With the below simple ten lines script, you can disassociate the public IP address from your Azure Firewall instance.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Connect-AzAccount
$context = Get-AzSubscription -SubscriptionId <YourSubscriptionId>
Set-AzContext $context
$rgName = '<PublicIpRgName>'
$pipName = '<PublicIpName>'
$azName = '<AzureFirewallName>'
$pip = Get-AzPublicIpAddress -Name $pipName -ResourceGroupName $rgName
$azFw = Get-AzFirewall -Name $azName -ResourceGroupName $rgName
$azFw.RemovePublicIpAddress($pip)
$azFw | Set-AzFirewall

First of all, you have to connect to your Azure account from Powershell. The next two steps are optional - only required if you want to change subscription, f.g. because you logged into another one by default.

In the next three lines, we are configuring some useful variables - we are defining in which Resource Group the public IP and the Azure Firewall are existing and what are the names of the resources.

The last four lines are the most important - we are taking the information about public IP and Azure Firewall, we are removing the address from the firewall, and then we are committing the changes by the last line.

To associate the existing public IP address to the firewall, you have to change the ninth line of the above script:

1
$azFw.AddPublicIpAddress($pip)

I hope it will be useful for you!

Newsletter

Thank you for visiting my website. I hope you enjoyed content which I prepared and learned something valuable from it. If you want to be informed about my next entries or occasionally get a message with a collection of some interesting links, please subscribe to my newsletter. I will be extremely pleased if you do this and join my community!

  • By clicking button below you agree to send you news from my blog, about my products and services. Above data are stored in Mailchimp and I do not share them to anyone. More info you can find in privacy policy.

comments powered by Disqus