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
- Which type of PowerShell loop should you be using?
- Working with CSV files in PowerShell
- Reading and extracting values from XML files with PowerShell
- Working with dates in PowerShell revisited
- PowerShell regular expressions: Making string evaluation easier
More Quick Tips articles
- New from Microsoft: Azure Security Center onboarding guide
- Fixing Azure Key Vault when moving to a different tenant
- Restore Azure Key Vault using just two PowerShell cmdlets
- This overlooked feature in Visual Studio Code can speed release time
- Enabling Front Door managed certificates in Azure: Status update