http://pingforinfo.com/powercli-script-to-set-perennial-reservation-to-all-rdm-luns-in-a-cluster/

 

Please find the Powercli script for configuring Perennial reservation on all RDM luns in a ESXi Cluster. Please change the value for following variables before you execute the script.


$vcenter = “vCenter.vmtest.com”
$dCenter = “123456”
$cluster = “Production Hypervisor”


This is the flow of script execution.


  1. Get the list of RDM LUNs from the cluster.

  2. Check the current perennial reservation status of the RDM. If it’s TRUE, no changes will be applied.

  3. If the status is FALSE, the perennial reservation will be set on the LUN.

  4. Script will query the latest status and the status will be displayed.


The result, after executing the script, looks something like this.


perinnial reservation

 

Please see attached script.

# This script will set the parameter Perennially Reservations to True on RDM Luns in a cluster

#$vcenter = #"vCenter Name "

#$dCenter = #"Datacenter Name"

#$cluster = #"Cluster Name"

 

$vcenter = "vCenter.vmtest.com"

$dCenter = "123456"

$cluster = "Production Hypervisor"

 

#-------------------------------------------------------------------------

 

# Do not modify bellow script

#-------------------------------------------------------------------------

 

#Add-PSSnapIn VMware* -ErrorAction SilentlyContinue

 

$connected = Connect-VIServer -Server $vcenter | Out-Null

 

$clusterInfo = Get-Datacenter -Name $dCenter | get-cluster $cluster

$vmHosts = $clusterInfo | get-vmhost | select -ExpandProperty Name

$RDMNAAs = $clusterInfo | Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select -ExpandProperty ScsiCanonicalName -Unique

 

foreach ($vmhost in $vmHosts) {

$myesxcli = Get-EsxCli -VMHost $vmhost

 

foreach ($naa in $RDMNAAs) {

 

$diskinfo = $myesxcli.storage.core.device.list("$naa") | Select -ExpandProperty IsPerenniallyReserved

$vmhost + " " + $naa + " " + "IsPerenniallyReserved= " + $diskinfo

if($diskinfo -eq "false")

{

write-host "Configuring Perennial Reservation for LUN $naa......."

$myesxcli.storage.core.device.setconfig($false,$naa,$true)

$diskinfo = $myesxcli.storage.core.device.list("$naa") | Select -ExpandProperty IsPerenniallyReserved

$vmhost + " " + $naa + " " + "IsPerenniallyReserved= " + $diskinfo

}

write-host "----------------------------------------------------------------------------------------------"

}

}

 

Disconnect-VIServer $vcenter -confirm:$false | Out-Null