Microsoft Virtualization Discussions

Question regarding Convertto-formattednumber

JGPSHNTAP
7,101 Views

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

13 REPLIES 13

cknight
7,075 Views

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

JGPSHNTAP
7,075 Views

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...

JGPSHNTAP
7,074 Views

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.

cknight
7,074 Views

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

JGPSHNTAP
7,074 Views

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..

JGPSHNTAP
7,074 Views

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. 

cknight
7,074 Views

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.

JGPSHNTAP
7,074 Views

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.

JGPSHNTAP
7,074 Views

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 $_.name | Select @{E={convertto-formattednumber $_.volumesize datasize "0.00"}

Write-host "Volume name: " $_.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?

cknight
6,315 Views

Here's one way:

PS C:\> $volSizeMap = @{}

PS C:\> $vols | % { $volSizeMap[$_.Name] = (Get-NaVolSize $_ | select -ExpandProperty VolumeSize | ConvertTo-FormattedNumber -Type DataSize -NumberFormatString "0.00") }

PS C:\> $volSizeMap | ft -AutoSize

JGPSHNTAP
6,315 Views

Clinton -

This is brilliant as usual.  I'm sitting here wondering how you are stuffing the array, and why I can' t pull aggregate information as well..   I basically want $volsizemap array to encompass stuff from get-navol, So example, I really want $_.totalsize $_.totalused - etc... I'm having trouble with the concept of this array.   I just don't understand it and i'll be the first to admit it.

cknight
6,315 Views

It isn't an array, it's a hashtable that maps volume name to formatted volume size.  There are plenty of other ways to do what you want, but this seemed straightforward enough.

JGPSHNTAP
6,315 Views

Ah - hash table, Cool.  Thx...

So.. anyways,.. I still need to get it in a format where it shows all the true columns, better for report, but here's my thought process around scripting new vols when provisioning snapmirror targets or just messing around in the lab

$vols | % {

if ($_.snapshotpercentreserved -eq 0) {

write-host "No Snapshot Reserve Name: " $_.name }

new-navol -name $_. name -aggregate aggr1 -spacereserve none -size $_.totalsize -controller $dstfiler

elseif ($_.snapshotpercentreserved -gt 0) {

write-host "Snapshot reserve volume: " $_.name  "`tSnapshotReserve%" $_.snapshotpercentreserved}

$volsize = get-navolsize $_.name

new-navol -name $_. name -aggregate aggr1 -spacereserve none -size $volsize  -controller $dstfiler

}

## Close loop

}

That was my thought process... I haven't tested the above code, but in theory it should work. 

Public