Subscribe
Accepted Solution

Ontap Powershell CLI for Volume Options

Hi,

I've created the following Powershell command to sort through our volumes and their options to produce a list of volumes that have the fs_size_fixed value set to on.

Get-NaVol | Get-NaVolOption | where{$_.Name -eq "fs_size_fixed" -and $_.Value -eq "on"}

This currently works and produces the list below, however is there a way that I can list the volume name in one of the columns ?

Name                                                                            Value

----                                                                            -----

fs_size_fixed                                                                   on

fs_size_fixed                                                                   on

fs_size_fixed                                                                   on

fs_size_fixed                                                                   on

fs_size_fixed                                                                   on

fs_size_fixed                                                                   on

Re: Ontap Powershell CLI for Volume Options

Hi David, you can create custom tables with select object expressions in powershell to get the required output, here's the code which would give the required output

Get-NaVol | select @{l='VolumeName';e={$_.name}},@{l='Volume Property Name';e={Get-NaVoloption $_.name | Where-Object {$_.name -eq "fs_size_fixed" -and $_.value -eq "off"} | select -ExpandProperty name}}, `

@{l='Volume Property Value';e={Get-NaVoloption $_.name | Where-Object {$_.name -eq "fs_size_fixed" -and $_.value -eq "off"} | select -ExpandProperty value}}

Below is a screencap pasted for the output for this command which emits objects as output.

Re: Ontap Powershell CLI for Volume Options

Hi Vinith, thanks for that we are almost there. As the output ends up listing on and off values. If you set one of your demo volumes fs_size_fixed to on and then run the same command you will see that the volumes that are set to on, will display <> under the column Volume Property Name and Volume Property Value. If possible I just want to show volumes with the on value ?

Re: Ontap Powershell CLI for Volume Options

Hi David,

I Guess you can just modify the snippet to $_.value -eq "on" as below and re-run, then it would display volumes with on value, can you give this a try and see if it helps

 

Get-NaVol | select @{l='VolumeName';e={$_.name}},@{l='Volume Property Name';e={Get-NaVoloption $_.name | Where-Object {$_.name -eq "fs_size_fixed" -and $_.value -eq "on"} | select -ExpandProperty name}}, `

@{l='Volume Property Value';e={Get-NaVoloption $_.name | Where-Object {$_.name -eq "fs_size_fixed" -and $_.value -eq "on"} | select -ExpandProperty value}} | `

?{$_."Volume Property Value" -eq "on"}

Re: Ontap Powershell CLI for Volume Options

excellent thanks Vinith that last one worked with the additional ?{$_."Volume Property Value" -eq "on"}

You might guess my next question, I want to set all the volumes that have fs_size_fixed with a value of on to off, will the following work

$volumes = Get-NaVol | select @{l='VolumeName';e={$_.name}},@{l='Volume Property Name';e={Get-NaVoloption $_.name | Where-Object {$_.name -eq "fs_size_fixed" -and $_.value -eq "on"} | select -ExpandProperty name}},@{l='Volume Property Value';e={Get-NaVoloption $_.name | Where-Object {$_.name -eq "fs_size_fixed" -and $_.value -eq "on"} | select -ExpandProperty value}} | ?{$_."Volume Property Value" -eq "on"}

$volumes | Set-NaVolOption fs_size_fixed off


Re: Ontap Powershell CLI for Volume Options

Hi David,

Please try below and let me know if it works.

$volumes | ForEach-Object { Set-NaVolOption -Name $_.VolumeName -Key $_."Volume Property Name" -Value off }