Set RDMs to Perennially Reserved for all hosts under a vCenter server

Posted by

In most production environments business as usual activities, user errors or business critical changes can sometime make environment deviate from best practices. One such best practice for vSpehre environment is to have RDM devices used by MS cluster set as Perennially Reserved.

This blog provides you a quick way to fix the deviations from this best practice.

Script Flow:
Step 1:

Prepare a list of Naa IDs that are used as RDMs in the setup. There are plenty of blogs and community links that cover this part. Below are a few

The output of each method is different but all of them give you the NAA ID for the RDM device.

Step 2:

Format the list of Naa IDs for use with this script. This script expects the input file format as under

Step 3:

Execute the below code after updating the csv file location

$rdms=Import-Csv C:\Users\vmZoneBlog\RDMs.csv
$myhosts = Get-VMHost
foreach ($myhost in $myhosts)
$myesxcli= get-esxcli -VMHost $myhost
$devices=Get-ScsiLun -VmHost $myhost.Name | select CanonicalName
    foreach ($device in $devices)
        foreach ($rdm in $rdms)
        if($device.CanonicalName -eq $rdm.Naa_ID)
                $isreserved = $$device.CanonicalName) | select -Property IsPerenniallyReserved
                 if ($isreserved.IsPerenniallyReserved -eq $false)
                    Write-Host("Setting "+$rdm.Naa_ID+" on "+ $myhost.Name + " to Perennially Reserved")
                    $$false,$device.CanonicalName, $true)
                    Write-Host($rdm.Naa_ID+ " on " + $myhost.Name +" is allready Perennially Reserved")

Make sure to update the input csv location in line 1