Microsoft Virtualization Discussions

Get-NaAggrSpace

JSHACHER11
8,548 Views

Hi guys,

I am trying to export to CSV a list/table of Aggregate space stats. This isn't working:

================================================

$aggr = Get-NaAggrSpace

$customobject = new-object psobject

add-member -inputobject $customobject -membertype noteproperty -name Aggregate -value $aggr.AggregateName

add-member -inputobject $customobject -membertype noteproperty -name Free_Size -value $aggr.SizeFree

add-member -inputobject $customobject -membertype noteproperty -name Snapshots_Use -value $aggr.SizeSnapUsed

add-member -inputobject $customobject -membertype noteproperty -name Used -value $aggr.SizeUsed

add-member -inputobject $customobject -membertype noteproperty -name Volumes_Use -value $aggr.SizeVolumeUsed

add-member -inputobject $customobject -membertype noteproperty -name Volumes -value $aggr.Volumes

$customobject | export-csv c:\aggr_size.csv -notypeinformation

===============================================

what would be the best way? I would also like to export it in different units (MB, GB,..)

Thank you

Joel

16 REPLIES 16

vinith
8,507 Views

This should work for you

Get-NaAggrSpace | select AggregateName,@{l='SizeFree(GB)';e={([math]::Round([decimal]($_.SizeFree)/1gb,2))}},@{l='SizeSnapUsed(GB)';e={([math]::Round([decimal]($_.SizeSnapUsed)/1gb,2))}},@{l='SizeUsed(GB)';e={([math]::Round([decimal]($_.SizeUsed)/1gb,2))}},@{l='SizeVolumeUsed(GB)';e={([math]::Round([decimal]($_.SizeVolumeUsed)/1gb,2))}},@{label="Volumes";expression={$_.volumes -join ","}} | Export-Csv "c:\vins.csv"

JSHACHER11
8,507 Views

thanks - I will try that now

what does the  '-join' do?

JSHACHER11
8,507 Views

is there an easy way to change the size from GB units to MB globally?

vinith
8,509 Views

you can just replace 'gb' with 'mb' in above code to get your output in mb. check this technet link http://technet.microsoft.com/en-us/library/ee692684.aspx

vinith
8,507 Views

The join operator concatenates a set of strings into a single string., for mode details check out

PS C:\Users\vinith> Get-Help about_join

JSHACHER11
8,507 Views

the output isn't working. I am getting rows instead of columns in the CSV file

vinith
8,507 Views

this is how the output should look like.

JSHACHER11
8,507 Views

this is what I am getting - I need a list of volumes in a column, not a row - is that possible? I guess we need to create a file for each aggregate?

AggregateNameSizeFree(GB)SizeSnapUsed(GB)SizeUsed(GB)SizeVolumeUsed(GB)Volumes

aggr0                             2GB                                   1GB                        1GB                  1GB                       vol0, vol1, vol2, vol3, vol4,....

JGPSHNTAP
8,507 Views

Joel -

Your first example isn't going to work because you don't loop through the array.    Also, you don't really need to create custom objects in this example b/c they are already created

Why do you need a list of volumes in a row?  

JSHACHER11
7,863 Views

"Why do you need a list of volumes in a row?"

easy to read

I can have the list of volumes in a separated list though

JSHACHER11
7,863 Views

why is this not working:

$aggr = Get-NaAggrSpace

$aggr.SizeFree

JGPSHNTAP
7,863 Views

Joel - do a search for an excel report I wrote that will give you a dashboard, Try that out and see if thats what you need

JGPSHNTAP
7,863 Views

Joel -

Slow down a little ...

It's not working because it's an array of objects.  That's why.  I know your just getting started with PS, you need to read up on it a little.  Can't all be trial by fire

JGPSHNTAP
7,863 Views

yeah

JSHACHER11
6,930 Views

that was last year and in there you stated that "I'm in no way a powershell expert" - I can tell you that it's not true anymore

thanks for the help

Public