0

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 2

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

yes. doesn't give good output
Can you elaborate? There is also the $customsa | Out-GridView which will open the results in a new window with more room.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.