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
- Neat trick: Organizing and formatting messy PowerShell output
- Adding help to your custom PowerShell cmdlets: Step-by-step guide
- Manage Microsoft Teams quickly and easily with PowerShell
- Building custom PowerShell cmdlets the easy way with modules
- Adding custom error messages to your PowerShell scripts
More Quick Tips articles
- Using location in a consistent way in your ARM template parameters
- Using environment as variables in your Azure DevOps pipelines
- Removing Log Analytics with the soft-delete option
- Using conditions in ARM templates when deploying infrastructure-as-code
- Monitor your Azure VM from your mobile device by scanning a QR code