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.
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.
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.
More PowerShell Basics articles
- Multilingual PowerShell scripts: A must for multinational organizations
- Reading text files the easy way with PowerShell and Linux bash shell
- Managing Azure Windows Virtual Desktop using PowerShell
- Conquer the world with PowerShell global variable
- PowerShell print: Output at your fingertips, to screen or file