Last active
October 4, 2018 21:56
-
-
Save ljtill/20ef29a8dc89613b9873b90ac5a3e13c to your computer and use it in GitHub Desktop.
Provides the ability to report on Storage Account access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-AzureRmStoragePublicAccess { | |
| [CmdletBinding()] | |
| param () | |
| begin { | |
| $subscriptions = Get-AzureRmSubscription | Out-GridView -Title "Microsoft Azure - Subscriptions" -PassThru | |
| } | |
| process { | |
| $results = @() | |
| foreach ($subscription in $subscriptions) { | |
| Set-AzureRmContext -SubscriptionObject $subscription | Out-Null | |
| $storageAccounts = Get-AzureRmStorageAccount | |
| foreach ($storageAccount in $storageAccounts) { | |
| $context = (Get-AzureRmStorageAccount -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccount.StorageAccountName).Context | |
| $containers = Get-AzureStorageContainer -Context $context | |
| foreach ($container in $containers) { | |
| $object = New-Object System.Object | |
| $object | Add-Member -Type NoteProperty -Name "ResourceGroupName" -Value $storageAccount.ResourceGroupName | |
| $object | Add-Member -Type NoteProperty -Name "StorageAccountName" -Value $storageAccount.StorageAccountName | |
| $object | Add-Member -Type NoteProperty -Name "ContainerName" -Value $container.Name | |
| $object | Add-Member -Type NoteProperty -Name "PublicAccess" -Value $container.PublicAccess | |
| $object | Add-Member -Type NoteProperty -Name "LastModified" -Value $container.LastModified | |
| $object | Add-Member -Type NoteProperty -Name "Location" -Value $storageAccount.Location | |
| $results += $object | |
| } | |
| } | |
| } | |
| } | |
| end { | |
| $results | Out-GridView -Title "Microsoft Azure - Storage Accounts - Access" | |
| $results | Export-Csv -Path ([Environment]::GetFolderPath("Desktop") + "\" + "StorageAccounts" + ".csv") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment