The community will be undergoing maintenance soon, requiring Read-Only mode. Click to learn more.

Microsoft Virtualization Discussions

Get-NAVolOptions with Options Name?

christoph

hi,

i've a maybe dumb questions but i can't find a solution for.

i'm trying to get the fractional reserve setting of all my volumes. As far as i got:

Get-NaVolOption vol_name

returns all options set on the volume. but every try to just get the fractional reserve option failed. finally i came out with something like:

Get-NaVol vol_* | % {  $string = $_.name + "|" + (get-navoloption $_)[6]; write-host $string}

i can't believe it's not possible to do address the properties by name like:

Get-NAVolOption -Name vol_name -Option fractional_reserve

or

$options = Get-NAVolOption -Name vol_name

Write-Host $options["fractional_reserve"]

Can i ALWAYS rely on fractional reserve property being the 6th value in the array? can this change? (as far as i've seen on all of my volumes the fractional reserve setting is always the 6th value)

wouldn't it be easier to return not an System.Array but an System.collections.hashtable?

(workaround or me:

$options = Get-NAVolOption -Name vol_name

$hashoptions = @{}

$options | %{ $hashoptions.Add($_.name,$_.value)}

write-host $hashoptions.fractional_reserve

)...

BG Christoph

1 ACCEPTED SOLUTION

bsti

You're getting back an object array of hash tables.  Unfortunately, I don't think you can easily index a collection like that.  Try this:

((Get-NaVolOption volumename) | ? { $_.Name -ieq "fractional_reserve" }).Value

If get-NaVolOption returned a single hashtable instead of an array of tables, you could use an indexer on it and that would make it a bit more friendly.  Perhaps a suggestion for the next revision of the ONTAP toolkit?

View solution in original post

5 REPLIES 5

VIRTUALLYMIKEB

Hey gents,

 

I used similar tactics to get the fractional reserve setting, among others here

 

http://virtuallymikebrown.com/2014/11/28/using-powershell-to-prevent-thinly-provisioned-netapp-luns-from-going-offline-part-i/

 

Cheers,

 

Mike

bsti

You're getting back an object array of hash tables.  Unfortunately, I don't think you can easily index a collection like that.  Try this:

((Get-NaVolOption volumename) | ? { $_.Name -ieq "fractional_reserve" }).Value

If get-NaVolOption returned a single hashtable instead of an array of tables, you could use an indexer on it and that would make it a bit more friendly.  Perhaps a suggestion for the next revision of the ONTAP toolkit?

View solution in original post

aschneider146

You can use the foreach statement to iterate over the hash table that is returned.

$options = get-navol | select -first 1 | Get-NaVolOption

foreach ($opt in $options) {$opt | ? {$_.Name -like "fract*"}}

cknight

The design goal was consistency between Get-NaVolOption, Get-NaAggrOption, and Get-NaOption.  But Get-NaOption returns values with three fields (key, value, cluster constraint) that don't lend themselves to hashtables.  However, the utility of accessing option values in a hashtable is obvious, so we'll consider that for a future release.  I suspect that for compatibility the default behavior would remain, and something like a -Hashtable switch parameter would yield a single table instead.  In the meantime, the suggested code for copying the values into a hashtable works well.

webfarm_aruba

I personally use this way here:

Get-NaVol | %{

     $vol = $_

     $obj = $vol |Get-NaVolOption |? {$_.Name -eq "fractional_reserve"} |select @{N="VolName";E={$vol.Name}},@{N="FractionalReserve";E={if ($_.Value -eq 0) {"Off"} else {"On"}}}

}

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public