Microsoft Virtualization Discussions

Question regarding Convertto-formattednumber

So this is a basic simple question, when using the convertto-formattednumber cmdlet it nicely formats the data into either TB, GB, MB, etc....   I've been looking at the cmdlet and seeing if there is a way to make the output consistent in either all GB or TB, etc..

I've been unsuccessful.

What i've done so far, it's ugly, but it's my desired result is something like this..

get-navol | Select Name,Aggregate,@{E={[Math]::round(($_.Totalsize/(1024*1024))/1024,2)};Name = "Total Size (GB)"},@{E={[Math]::round(($_.sizeused/(1024*1024))/1024,2)};N = "Used (GB)"},@{E={[Math]::round(($_.Available/(1024*1024))/1024,2)};N = "Available (GB)"} | Sort Aggregate | ft -autosize

The only reason why i'm doing this is quick calculation to excel to figure out free space on the aggrs quickly.. you can just add them up in excel if you pipe to export-csv

Just curious if there was an easier way


Re: Question regarding Convertto-formattednumber

ConvertTo-FormattedNumber doesn't accept units as an argument.  I wrote that one principally to support the Toolkit's data formatters.

If you just want to add up the available space, there's no need to export to Excel.

PS C:\> Get-NaVol | Measure-Object Available -Sum | Select-Object -ExpandProperty Sum | ConvertTo-FormattedNumber -Type DataSize

338 GB

Re: Question regarding Convertto-formattednumber

Clinton - Your a genius!

Well that sure makes things easier...

get-navol | measure-object Totalsize,Available,sizeused -Sum | select -expandproperty Sum | Convertto-formattednumber -type Datasize

Now, I just need to play around with getting into each aggr info.. sort of like aggr show_space -g, but neater...

Re: Question regarding Convertto-formattednumber

There is one issue i am having and i'm wondering what it could be..

from the console if i run aggr show_space -g or vol size on a specific volume it shows as 4560GB, but with powershell it shows 3.5tb.  Wierd, I can't figure that one out.

Re: Question regarding Convertto-formattednumber

You may have to consider things like snapshot reserve, WAFL reserve, etc.

Re: Question regarding Convertto-formattednumber

Clinton - Good point.. I just checked it's totally snapshot reserve.. Omg, I totally overlooked that... I know this is off topic from the original thread, but to me that makes things pretty confusing.. I was under the impression that get-navol was similiar to vol size where it tells you the entire volume.. If snapshot reserve is enabled at 20% it can totally throw off the automation of scripting..

Re: Question regarding Convertto-formattednumber

Clinton -

get-navol vol0 | get-navolsize | Select @{E={convertto-formattednumber $_.volumesize datasize "0.00"};N = "Volumesize"}

That wll give us the true vol size if snapshot reserve is on.  Hmm. To me, I feel like we should represent that in Get-navol,

For example, if I want to provision a new filer, i use the $_.totalsize property to do so, but that's technically incorrect. 

Re: Question regarding Convertto-formattednumber

I agree the APIs for space reporting aren't perfect.  Adding a call to the vol-size API inside Get-NaVol would add an API call for each volume, whereas Get-NaVol gets all the data in a small number of calls, so we'd not want to slow it down like that.  At least it's better in Cluster Mode.

Re: Question regarding Convertto-formattednumber

Clinton -

Thx for the reply - I agree with your statement on multiple calls, but the get-navol totalsize isn't a true representation.. I can't believe i've missed this before, most of the time, i deal with snapshot reserve of 0, but it just so happens, I was looking at this closer today and they didn't jive.

Re: Question regarding Convertto-formattednumber

So Clinton - i've been racking my brain for a little to try to figure out the best way to get a better representation of the storage..

I was trying stuff like

$vols = get-navol

$vols | % {

$volsize = get-navolsize $ | Select @{E={convertto-formattednumber $_.volumesize datasize "0.00"}

Write-host "Volume name: " $ "`tVolumeSize: " $volsize


But that totally fails..

Ultimately, I would like to be ale to get true volume size as to when we build a new filer, and snapshot reserve is set I can get the true volume size and as well for reporting..

Where am I going wrong here?