Microsoft Virtualization Discussions

Ontap Powershell CLI for Volume Options

davidrnexon
6,974 Views

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

1 ACCEPTED SOLUTION

vinith
6,973 Views

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

View solution in original post

5 REPLIES 5

vinith
6,973 Views

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.

davidrnexon
6,973 Views

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 ?

vinith
6,974 Views

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

davidrnexon
6,973 Views

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


vinith
6,973 Views

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 }

Public