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.

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.

$tmpStgRules.VirtualNetworkRules.VirtualNetworkResourceId.Contains("/subscriptions/<subscriptionID>/resourceGroups/<ResourceGroupName>/providers/Microsoft.Network/virtualNetworks/<VirtualNetworkName>/subnets/<SubnetName>")

Anderson Patricio

Anderson Patricio is a Canadian MVP in Cloud and Datacenter Management, and Office Server and Services, besides of the Microsoft Award he also holds a Solutions Master (MCSM) in Exchange, CISSP and several other certifications. Anderson contributes to the Microsoft Community with articles, tutorials, blog posts, twitter, forums and book reviews. He is a regular contributor here at Techgenix.com, MSExchange.org, ITPROCentral.com and Anderson Patricio.org (Portuguese).

Share
Published by
Anderson Patricio

Recent Posts

Azure DevOps Wiki: Manage your project documentation and collaboration

Not being able to find project documentation is way too common. Use Azure DevOps’ built-in…

2 days ago

Samsung Unpacked 2020: Galaxy S20, Galaxy Z Flip, and more

Samsung is again the first major company to roll out new smartphones in the new…

2 days ago

PhotoSquared data leak exposes users’ photos, information

PhotoSquared has experienced a data leak, mainly because the popular U.S.-based photo app failed to…

2 days ago

Moving data from an Azure VM to Storage Account with AzCopy

Here’s an elegant and modern way to move data from your Azure virtual machine to…

3 days ago

A lot not to like: Analysis of recent Facebook data breach

The effects of the recent Facebook data breach are still being felt. In this new…

3 days ago

Exchange 2019: Building an environment from scratch

Are you finally ready to take the plunge into Exchange 2019? If you are building…

3 days ago