Microsoft Virtualization Discussions

get volsize and aggrsize

JSHACHER11
7,127 Views

Hi guys,

I'm after a script that will show me volumes over 90% full (total, available, used) and then will show the same thing in the containing aggregates (total, available, used)

this is what I use now to get the vol size:

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

Import-Module Dataontap

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 90 }

}

$filer = Read-Host "Enter the filer name"

$user = "root"

Connect-NaController -Name $filer -Credential $user

Get-VolOverEighty

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

This works fine but I want it to report the size in the containing aggregates as well - is that possible?

Cheers

1 ACCEPTED SOLUTION

vinith
7,124 Views

This should give you that information, Note that i have appended the Aggr Size information in TB

Function Get-VolOverEighty {

Get-NaVol | ? { $_.used -gt 90 } | select name,aggregate,used,@{Name="VolumeAvailable(GB)";Expression={[math]::Round([decimal]$_.Available/1gb,0)}},`

@{Name="VolumeSizeTotal(GB)";Expression={[math]::Round([decimal]$_.sizetotal/1gb,0)}}, `

@{Name="AggregateSizeTotal(TB)";Expression={[math]::Round([decimal] ((Get-NaAggr -Name $_.Aggregate | select -ExpandProperty SizeTotal)/1tb),2)}},`

@{Name="AggregateSizeAvailable(TB)";Expression={[math]::Round([decimal] ((Get-NaAggr -Name $_.Aggregate | select -ExpandProperty SizeAvailable)/1tb),2)}},`

@{Name="AggregateSizeUsed(TB)";Expression={[math]::Round([decimal] ((Get-NaAggr -Name $_.Aggregate | select -ExpandProperty SizeUsed)/1tb),2)}}

}

Get-VolOverEighty

View solution in original post

16 REPLIES 16

vinith
7,125 Views

This should give you that information, Note that i have appended the Aggr Size information in TB

Function Get-VolOverEighty {

Get-NaVol | ? { $_.used -gt 90 } | select name,aggregate,used,@{Name="VolumeAvailable(GB)";Expression={[math]::Round([decimal]$_.Available/1gb,0)}},`

@{Name="VolumeSizeTotal(GB)";Expression={[math]::Round([decimal]$_.sizetotal/1gb,0)}}, `

@{Name="AggregateSizeTotal(TB)";Expression={[math]::Round([decimal] ((Get-NaAggr -Name $_.Aggregate | select -ExpandProperty SizeTotal)/1tb),2)}},`

@{Name="AggregateSizeAvailable(TB)";Expression={[math]::Round([decimal] ((Get-NaAggr -Name $_.Aggregate | select -ExpandProperty SizeAvailable)/1tb),2)}},`

@{Name="AggregateSizeUsed(TB)";Expression={[math]::Round([decimal] ((Get-NaAggr -Name $_.Aggregate | select -ExpandProperty SizeUsed)/1tb),2)}}

}

Get-VolOverEighty

JSHACHER11
7,099 Views

thanks

I'm getting this:

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

Missing expression after ','.

+ @{Name="VolumeSizeTotal(GB)";Expression={[math]::Round([decimal]$_.sizetotal/1gb,0)}}, <<<< `

    + CategoryInfo          : ParserError: (,:String) [], ParseException

    + FullyQualifiedErrorId : MissingExpressionAfterToken

vinith
7,099 Views

Just copy paste this.

Function Get-VolOverEighty { 

Get-NaVol | ? { $_.used -gt 90 } | select name,aggregate,used,@{Name="VolumeAvailable(GB)";Expression={[math]::Round([decimal]$_.Available/1gb,0)}},` 

@{Name="VolumeSizeTotal(GB)";Expression={[math]::Round([decimal]$_.sizetotal/1gb,0)}}, ` 

@{Name="AggregateSizeTotal(TB)";Expression={[math]::Round([decimal] ((Get-NaAggr -Name $_.Aggregate | select -ExpandProperty SizeTotal)/1tb),2)}},` 

@{Name="AggregateSizeAvailable(TB)";Expression={[math]::Round([decimal] ((Get-NaAggr -Name $_.Aggregate | select -ExpandProperty SizeAvailable)/1tb),2)}},` 

@{Name="AggregateSizeUsed(TB)";Expression={[math]::Round([decimal] ((Get-NaAggr -Name $_.Aggregate | select -ExpandProperty SizeUsed)/1tb),2)}}  

 

Get-VolOverEighty 

JSHACHER11
7,099 Views

Great, thanks

Is there a way to show every volume that is more than 90% full and pipe the snapmirror status of only those volumes?

JGPSHNTAP
7,100 Views

You can also use the built in cmdlet instead of all that math - convertto-formattednumber..

JGPSHNTAP
7,101 Views

As far as piping them to snapmirror status, you can either pipe them to snapmirror status, or create custom objects and then work that why.

I'm curious, why are you using a function?

JSHACHER11
7,101 Views

Thanks for the advice

1. "pipe them to snapmirror status, or create custom objects" - can you give an example please how to pipe the output of Get-VolOverEighty to Get-NaSnapmirror?

2. "why are you using a function?" - is that the wrong way? Please let me know how you would do it (I'm still a newbie...)

Cheers

Joel

JGPSHNTAP
7,101 Views

Yah.. Functions are not what you are after.. That is not the proper way to do thing in my opinion for this

For piping directly to snapmirror status

get-navol | get-nasnapmirror

JSHACHER11
7,101 Views

so in my case if I want to get the snapmirror status of (only) the volumes that are more than 90% full I should use this?

Get-VolOverEighty | GetNaSnapmirror

JGPSHNTAP
6,562 Views

Not really...

get-navol | ? {$_.used -gt 90} | get-nasnapmirror

JSHACHER11
6,562 Views

short and sweet , thanks

another question:

when I use the below command in a console it gives me nice table with 9 columns but in the script it gives a long list

get-navol | ? {$_.used -gt 90}

I tried to put Format-Table at the end (in the script) but it gives an error

Here's my script:

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

Import-Module Dataontap

write-host ""

write-host ""

write-host "This script will list volumes over 80% full, the containing aggregates and snapmirror relationships" -foregroundcolor yellow

write-host ""

write-host ""

write-host "You will also get an option to increase a volume size" -foregroundcolor yellow

write-host ""

write-host ""

$filer = Read-Host "Enter the filer name"

$user = Read-Host "Enter username"

Connect-NaController -Name $filer -Credential $user

get-navol | ? {$_.used -gt 80}

write-host ""

write-host ""

write-host "Here are the aggregates:" -foregroundcolor yellow

write-host ""

write-host ""

get-naaggr

write-host ""

write-host ""

write-host "and the snapmirror relationships:" -foregroundcolor yellow

write-host ""

write-host ""

get-navol | ? {$_.used -gt 80} | get-nasnapmirror

write-host ""

write-host ""

$ans = Read-Host -prompt "Would you like to increase one of the volumes? [Y/N]"

write-host ""

write-host ""

if ($ans -eq "N") {

exit

} else {

$vol = Read-Host "Enter volume name"

$size = Read-Host "How much more space do you want to give it? (example: +100g)"

Set-NaVolsize -Name $vol -NewSize $size -Confirm

Write-Host ""

Write-Host ""

Write-Host "Check the new size:" -foregroundcolor yellow

Write-Host ""

Write-Host ""

Get-NaVol -Name $vol | select name,used,@{Name="Available Size (in GB)";Expression={[math]::truncate($_.Available/1gb)}},@{Name="Total Size (in GB)";Expression={[math]::truncate($_.sizetotal/1gb)}}

}

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

JSHACHER11
6,562 Views

I actually use 'truncate':

get-naaggr | select name,@{Name="Total Size (in GB)";Expression={[math]::truncate($_.totalsize/1gb)}}

JGPSHNTAP
6,562 Views

You can do it that way, but the boys at netapp wrote an awesome cmdlet convertto-formattednumber.. Check that one out

JGPSHNTAP
6,560 Views

Wow.. I have no idea what you are trying to accomplish.. This script is all over the place man...

Take a look at the multi report i sent you for reporting..

Do you have onCommand installed?

JSHACHER11
6,560 Views

OK, I cracked it. You just need to add Out-String and the Format-Table will look fine. Here's the new script:

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

Import-Module Dataontap

write-host ""

write-host ""

write-host "This script will list volumes over 80% full, the containing aggregates and snapmirror relationships" -foregroundcolor yellow

write-host ""

write-host ""

write-host "You will also get an option to increase a volume size" -foregroundcolor yellow

write-host ""

write-host ""

$filer = Read-Host "Enter the filer name"

$user = Read-Host "Enter username"

Connect-NaController -Name $filer -Credential $user

get-navol | ? {$_.used -gt 80} | select name,used,@{Name="Available Size (in GB)";Expression={[math]::truncate($_.Available/1gb)}},@{Name="Total Size (in GB)";Expression={[math]::truncate($_.sizetotal/1gb)}} | ft -Autosize | Out-String

write-host ""

write-host ""

write-host "Here are the aggregates:" -foregroundcolor yellow

write-host ""

write-host ""

get-naaggr | select name,@{Name="Total Size (in GB)";Expression={[math]::truncate($_.totalsize/1gb)}},used,@{Name="Available Size (in GB)";Expression={[math]::truncate($_.available/1gb)}} | ft -Autosize | Out-String

write-host ""

write-host ""

write-host "and the snapmirror relationships:" -foregroundcolor yellow

write-host ""

write-host ""

get-navol | ? {$_.used -gt 80} | get-nasnapmirror | select source,destination | ft -Autosize | Out-String

write-host ""

write-host ""

$ans = Read-Host -prompt "Would you like to increase one of the volumes? [Y/N]"

write-host ""

write-host ""

if ($ans -eq "N") {

exit

} else {

$vol = Read-Host "Enter volume name"

$size = Read-Host "How much more space do you want to give it? (example: +100g)"

Set-NaVolsize -Name $vol -NewSize $size -Confirm

Write-Host ""

Write-Host ""

Write-Host "Check the new size:" -foregroundcolor yellow

Write-Host ""

Write-Host ""

Get-NaVol -Name $vol | select name,used,@{Name="Available Size (in GB)";Expression={[math]::truncate($_.Available/1gb)}},@{Name="Total Size (in GB)";Expression={[math]::truncate($_.sizetotal/1gb)}}

}

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

Thanks everyone

vinith
5,066 Views

Really Good to see that you have come up very well with grasping powershell. Keep up the hardwork

Public