简体   繁体   中英

Powershell: List/Export all Azure Storage Accounts with "NetworkRuleSet" property to CSV

Being a novice at Powershell, I'm trying the following:

  • Fetch all storage accounts from all subscriptions in Azure
  • List the "NetworkRuleSet" property (I want to check which.networks the account belongs to and if they have "All".networks checked)

I have found the below script, which essentially does part of it, but it lacks the option to fetch for all subscriptions and the export part. Any help is much appreciated.

BR, Jim

$Result=@()
$Storageaccounts = Get-AzStorageAccount
$Storageaccounts | ForEach-Object {
$storageaccount = $_
Get-AzStorageAccountNetworkRuleSet -ResourceGroupName $storageaccount.ResourceGroupName -AccountName $storageaccount.StorageAccountName | ForEach-Object {
$Result += New-Object PSObject -property @{ 
Account = $storageaccount.StorageAccountName
ResourceGroup = $storageaccount.ResourceGroupName
Bypass = $_.Bypass
Action = $_.DefaultAction
IPrules = $_.IpRules
Vnetrules = $_.VirtualNetworkRules
ResourceRules = $_.ResourceAccessRules
}
}
}
$Result | Select Account,ResourceGroup,Bypass,Action,IPrules,Vnetrules,ResourceRules```

To export the data to CSV file change the $Result line with below code.

$Result | Select Account,ResourceGroup,Bypass,Action,IPrules,Vnetrules,ResourceRules | Export-Csv -Path C:\Users\v-vedod\Desktop\9.csv

Below code will help you in setting content to script for that particular subscription but there is no option to run all the subscriptions.

Set-AzContext -Subscription (use your subscription id)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM