Validating virtual networks rules in a Storage Account using PowerShell

When managing access in a Storage Account in Microsoft Azure, the Azure Portal has a management interface that allows the cloud administrator to add and remove virtual networks easily.

virtual networks rules

But when scripting to validate to ensure consistency, PowerShell is the tool for the job. The cmdlet to retrieve the list of virtual network rules in a Storage Account is Get-AzStorageAccountNetworkRuleSet. However, it is recommended to store the output of the cmdlet in a variable. In this example, we are using $tmpSTGRules.

We can list the entire content, including action, VirtualnetworkResourceId, and State using $tmpSTGRules.VirtualNetworkRules, as depicted in the image below.

virtual networks rules

If we want to check if a specific subnet is configured within the existent Virtual Network Rules, we can use the following cmdlets and provide the resource id of the subnet. The output will be True if it is there or False in case the entry does not exist.


About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top