skip to Main Content

I created a custom object

$customsa = New-Object -TypeName psobject
$customsa | Add-Member -MemberType NoteProperty -Name Name -Value (Get-AzStorageAccount).StorageAccountName 
$customsa | Add-Member -MemberType NoteProperty -Name Tier -Value (Get-AzStorageAccount).AccessTier
$customsa | Add-Member -MemberType NoteProperty -Name Replication -Value (Get-AzStorageAccount).sku.Name
$customsa | Add-Member -MemberType NoteProperty -Name AccountKind -Value (Get-AzStorageAccount).kind
$customsa | Add-Member -MemberType NoteProperty -Name ResourceGroupName -Value (Get-AzStorageAccount).ResourceGroupName

The output is an array format

Output

However I want the output to show in a table format like this

Desired Table format

Thanks

2

Answers


  1. Have you tried?:

    $customsa | Format-Table
    # or
    $customsa | Out-GridView
    

    From your example:

    $customsa = New-Object -TypeName psobject
    $customsa | Add-Member -MemberType NoteProperty -Name Name -Value (Get-AzStorageAccount).StorageAccountName 
    $customsa | Add-Member -MemberType NoteProperty -Name Tier -Value (Get-AzStorageAccount).AccessTier
    $customsa | Add-Member -MemberType NoteProperty -Name Replication -Value (Get-AzStorageAccount).sku.Name
    $customsa | Add-Member -MemberType NoteProperty -Name AccountKind -Value (Get-AzStorageAccount).kind
    $customsa | Add-Member -MemberType NoteProperty -Name ResourceGroupName -Value (Get-AzStorageAccount).ResourceGroupName
    
    $customsa | Format-Table
    
    Login or Signup to reply.
  2. Get-AzStorageAccount is returning all of your storage accounts each time you run it so you are assigning the value of all storage accounts to each property when you’re using Add-Member.

    You should be able to get the same result using Select-Object which will create your psobject for you

    Get-AzStorageAccount |
        Select-Object StorageAccountName, AccessTier, Kind, ResourceGroupName, @{name = 'SKU'; expression = { $_.sku.name }} |
            Format-Table
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search