I’m using the below script to run:
$context = Get-AzContext
$storageAccounts = Get-AzResource -ResourceType 'Microsoft.Storage/storageAccounts'
[System.Collections.ArrayList]$saUsage = New-Object -TypeName System.Collections.ArrayList
foreach ($storageAccount in $storageAccounts) {
#list containers
$containers= Get-AzStorageContainer -ResourceGroupName $storageAccount.ResourceGroupName -StorageAccountName $storageAccount.Name
if($containers -ne $null){
foreach($container in $containers){
$StorageAccountDetails = [ordered]@{
SubscriptionName = $context.Subscription.Name
SubscrpitionID = $context.Subscription.Id
StorageAccountName = $storageAccount.Name
ContainerName = $container.Name
ResourceGroup = $storageAccount.ResourceGroupName
Location = $storageAccount.Location
size = $Storage.size
}
$saUsage.add((New-Object psobject -Property $StorageAccountDetails)) | Out-Null
}
}else{
$StorageAccountDetails = [ordered]@{
SubscriptionName = $context.Subscription.Name
SubscrpitionID = $context.Subscription.Id
StorageAccountName = $storageAccount.Name
ContainerName = $null
ResourceGroup = $storageAccount.ResourceGroupName
Location = $storageAccount.Location
size = $Storage.size
}
$saUsage.add((New-Object psobject -Property $StorageAccountDetails)) | Out-Null
}
}
$saUsage
But I’m getting an error, Please assist
2
Answers
The problem is described in the error message:
The cmdlet
Get-AzStorageContainer
does not support this parameter (and also does not suppport the-StorageAccountName
parameter).You might want to use the
-Context
parameter. However, this also requires you to use theGet-AzStorageAccount
cmdlet sinceGet-AzResource
does not return the Storage Account Context.The context contains all relevant properties that are required to connect to the storage account.
This is just for information. Using code along the lines below should solve this.
Please check the corresponding documentation for further details: https://learn.microsoft.com/en-us/powershell/module/az.storage/get-azstoragecontainer?view=azps-8.2.0
You can use the below python version code.