Azure API Management NSG Rules with PowerShell

When configuring or upgrading an Azure API Management stv2 instance on a Virtual Network (VNET) it is necessary to use a Network Security Group (NSG) and configure certain rules for the service to work.

“A network security group (NSG) is required to explicitly allow inbound connectivity, because the load balancer used internally by API Management is secure by default and rejects all inbound traffic.”

The Microsoft documentation lists these NSG rules, but it can be time-consuming to enter them manually using the Azure Portal, particularly if you have several API Management instances to upgrade or configure. This short code snippet uses PowerShell to deploy these rules, making the process much quicker and less prone to misconfiguration than the manual method.