NetApp and PoSH: Caveats with Get-NaVol and Set-NAVolAutosize

While working on a script to set the auto-grow max sizes on a given NetApp head (which I will post more about soon), I ran into the following problem.

The script uses Get-NAVol to find the existing volume total size. It then calculates a auto-grow max size by multiplying the existing volume total size by 1.2, to give an auto-grow size of 20% greater, and storing that number in a variable. It then uses Set-NAVolAutosize to set the new size.

This sounds like it should work, but instead Set-NAVolAutosize throws errors:

Set-NaVolAutosize : Invalid size: 386547056640.0

Where did that decimal come from? Let’s take a look. First, let’s examine the volume total size returned by Get-NaVol.

$Volumes = Get-NAVol
$Volumes[0].totalsize

354334801920

$Volumess[0].totalsize | gm

TypeName: System.Decimal

$Volumes.totalsize * 1.2 | gm

TypeName: System.Decimal

Well, that shows where our decimal is coming from! What happens if we set a variable to the number reported as the total volume size (354334801920)?

$number = 354334801920
$number | gm

TypeName: System.Int64

Using set-navolautosize using the variable $number works. So, it would appear that the type System.Decimal is causing the problem. The solution? Explicitly cast the result of multiplying the total volume size by 1.2 as an Int64. The below assumes $volume is a variable holding a single object from Get-NAVol.

$NewAutoSize = [int64]($Volume.totalsize * 1.2)

This solved my problem.

In the next week or two I will publish the entire script to set new auto-grow sizes.

 

~Daniel

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s