Microsoft Virtualization Discussions

size in MB/GB

JSHACHER11
11,825 Views

I was trying a script that will show more than 80% on all volumes - the output is in Bytes, how do I get it in GB?

Here is my command:

PS C:\Users\admin> Get-NaVol | select name,Aggregate,used,available,sizetotal | ? { $_.used -gt 80 } | ft -AutoSize

Name                               Aggregate      Used    Available     SizeTotal
----                                      ---------            ----     ---------          ---------
vol1                                 a_sata_1          86  67997564928  502511173632

vol2                                 a_sata_4          88 120586096640  971736350720
vol3                                 a_sata_1          89  42216550400  375809638400
vol4                                 a_sata_1          85  623957016576 4098472542208
vol5                                 sas_2               81 133199093760  692563476480

(....I know I need this somewhere >>>   /1gb )

1 ACCEPTED SOLUTION

vinith
11,825 Views

Hello, You can use hash tables to get this done.

Get-NaVol | select name,Aggregate,used,@{Name="Available(GB)";Expression={[math]::Round([decimal]$_.Available/1gb,0)}},@{Name="SizeTotal(GB)";Expression={[math]::Round([decimal]$_.sizetotal/1gb,0)}} | ? { $_.used -gt 80 } | ft -AutoSize


PS C:\Users\Vinith> Get-NaVol | select name,Aggregate,used,@{Name="Available(GB)";Expression={[math]::Round([decimal]$_.

Available/1gb,0)}},@{Name="SizeTotal(GB)";Expression={[math]::Round([decimal]$_.sizetotal/1gb,0)}} | ? { $_.used -gt 80

} | ft -AutoSize

View solution in original post

12 REPLIES 12

vinith
11,826 Views

Hello, You can use hash tables to get this done.

Get-NaVol | select name,Aggregate,used,@{Name="Available(GB)";Expression={[math]::Round([decimal]$_.Available/1gb,0)}},@{Name="SizeTotal(GB)";Expression={[math]::Round([decimal]$_.sizetotal/1gb,0)}} | ? { $_.used -gt 80 } | ft -AutoSize


PS C:\Users\Vinith> Get-NaVol | select name,Aggregate,used,@{Name="Available(GB)";Expression={[math]::Round([decimal]$_.

Available/1gb,0)}},@{Name="SizeTotal(GB)";Expression={[math]::Round([decimal]$_.sizetotal/1gb,0)}} | ? { $_.used -gt 80

} | ft -AutoSize

JSHACHER11
11,768 Views

sweet!

What does the 0 do >>>  $_.sizetotal/1gb,0

I've tried with and without the 0 and it gives me the same result

Thanks

JSHACHER11
11,768 Views

I was trying that for 2 filers with no success - what am I doing wrong?

+++++++++++++++++++++++++++++++++++++

Import-Module Dataontap

$myNetAppUser = "root"

$myNetAppArrayPass = "password1"

$myNetAppPass = ConvertTo-SecureString $myNetAppArrayPass -AsPlainText -Force

$myNetappCred = New-Object -TypeName system.Management.Automation.PSCredential -ArgumentList $myNetAppUser,$myNetAppPass

$ntapArrays = "filer1","filer2"

function Get-VolOverEighty {

Get-NaVol | select name,Aggregate,used,@{Name="Available(GB)";Expression={[math]::Round([decimal]$_.Available/1gb,0)}},@{Name="SizeTotal(GB)";Expression={[math]::Round([decimal]$_.sizetotal/1gb,0)}} | ? { $_.used -gt 80 } | ft -AutoSize

}

Foreach ($array in $ntapArrays)

{

connect-nacontroller $array -Credential $myNetAppArrayCred | Get-VolOverEighty

}

+++++++++++++++++++++++++++++++

I'm getting this:

Connect-NaController : Cannot bind argument to parameter 'Name' because it is null.

Thanks

vinith
11,768 Views

Replace below line

connect-nacontroller $array -Credential $myNetAppArrayCred | Get-VolOverEighty

with

connect-nacontroller $array -Credential $myNetAppCred | Get-VolOverEighty

$myNetAppArrayCred should be replaced with $myNetAppCred

JSHACHER11
11,768 Views

Connect-NaController : The requested name is valid, but no data of the requested type was found

At C:\scripts\over80_vol.ps1:22 char:21

+ connect-nacontroller <<<<  -name $array -Credential $myNetAppCred | Get-VolOverEighty

    + CategoryInfo          : NotSpecified: (:) [Connect-NaController], SocketException

    + FullyQualifiedErrorId : System.Net.Sockets.SocketException,DataONTAP.PowerShell.SDK.ConnectNaController

If I connect and run the command on each filer separately, everything works...

vinith
11,768 Views

can you reinstall PStoolkit and try?, Install the latest version PSToolkit v2.3

JSHACHER11
11,768 Views

I was running 2.3 - regardless, I reinstalled...same thing

cheers

vinith
11,768 Views

Its for rounding off values, for example if you use ($_.sizetotal/1gb,2) it would round off to two decimal places.

JGPSHNTAP
11,768 Views

Joel -

A few things I would do differently.

This is a little easier in my opinion

get-navol | Select Name,Aggregate,Used,@{Name="Available (GB)";E={convertto-formattednumber $_.available Datasize "0.00"}} | ? {$_.used -gt 80} | ft -autosize

But, I would do one more thing.  Have a search for a post I did about filer_report.  It will report on the filers with excel conditional formatting.  Give that a shot

JGPSHNTAP
8,449 Views

Actually, this is a little better,

get-navol | ? {$_.used -gt 80} | Select Name,Aggregate,@{Name="Used";E={Convertto-formattednumber $_.used percent}},@{Name="Available (GB)";E={convertto-formattednumber $_.available Datasize "0.00"}} | ft -autosize

You should always pipe in your where clause before you do any sorting.. Selecting...

JSHACHER11
8,449 Views

Cheers!

I'll give this and the filer_report a spin soon and let you know

BTW, the filer_report script looks awesome

Joel

JGPSHNTAP
8,449 Views

Enjoy

Public