VMware Cloud Community
MRoushdy
Hot Shot
Hot Shot

Script to set a LUN as perennially reserved

Hello,

I have more than 30 physical RDM LUNS mapped to more than 25 hosts, I need a script please to read from CSV (or any other suitable file format) to read the LUN unique ID and the host name please, the purpose of the script is to set all of the LUNs as perennially reserved

like this command:

esxcli storage core device setconfig -d naa.id --perennially-reserved=true

vEXPERT - VCAP-DCV - Blog: arabitnetwork.com | YouTube: youtube.com/c/MohamedRoushdy
0 Kudos
1 Reply
LucD
Leadership
Leadership

You could do something like this.

It assumes the CSV contains 2 columns like this

VMHost,CanonicalName

Import-Csv -Path .\lun.csv -UseCulture | %{

    $esxcli = Get-EsxCli -VMHost $_.VMHost

    $esxcli.storage.core.device.setconfig($false,$_.CanonicalName,$true)

    $esxcli.storage.core.device.list($_.CanonicalName) |

    Select @{N="Time";E={"{0:g}" -f (Get-Date).TimeOfDay}},Device,IsPerenniallyReserved

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos