Adding a bunch of IPs to an Azure NSG

So… there was an Azure outage today. Related to Azure Front Door. That was my evening gone!

As the resident PowerShell person on the incident call, as part of implementing some workarounds I had to add a bunch of IP addresses to a Network Security Group. I was given a text file with a bunch of IP addresses, and my task was to add them all to the NSG as “Deny” for “Inbound” traffic. Here’s what I did:

Had to piecemeal the code from various sources as the Microsoft Learn website was down so I couldn’t refer to it for the cmdlets and their switches.

Sweating Meme Gif

Two things the code could do with improving:

  • Check if the IP address/ subnet is already in the NSG
  • Fix the bit where I construct the rule name to remove any unaccepted characters than just the two I happened to encounter.