RDM – find assisgned and make sure assigned as Perennially Reserved

<#
.SYNOPSIS
Alan Harrington, copy and excute sections at a time to make sure runs okay
.DESCRIPTION
collects all rdms that are ASSIGNED to a vm and makes them as Perenially Reserved, if the rdm is not configured on the vm then it won’t set it.
.PARAMETER <paramName>
<Description of script parameter>
.EXAMPLE
<An example of using the script>
#>
$cluster = “vnesxcomp099_rdms”

#Get-cluster $cluster | get-vm | sort name | Get-HardDisk -DiskType “RawPhysical”,”RawVirtual” | Select Parent,ScsiCanonicalName
$rdmsattachedinclu = Get-cluster $cluster | get-vm | sort name | Get-HardDisk -DiskType “RawPhysical”,”RawVirtual” | Select Parent,ScsiCanonicalName
$rdmsscsinaa = $rdmsattachedinclu | select ScsiCanonicalName

#full list, sorted, unique
[array]$temp = $null
foreach ($rdmsscsi in $rdmsscsinaa){
$temp2 = $rdmsscsi.ScsiCanonicalName
$temp = $temp + $temp2}
foreach ($i in $temp) {
[string]$i = $i
$temp[$temp.IndexOf($i)] = $i.SubString(4)}
$rdmlist = $temp | sort | select -Unique
$rdmlist = $rdmlist | ForEach-Object {“naa.$_”}
#now that list is converted back to naa. time to set it

$vmhs = get-cluster $cluster | get-vmhost | sort name
$vmhsesxcli = $vmhs | get-esxcli
foreach($esxcli in $vmhsesxcli) {
# And for each RDM Disk
foreach($RDM in $rdmlist) {
# Set the configuration to “PereniallyReserved”.
# setconfig method: void setconfig(boolean detached, string device, boolean perenniallyreserved)
$esxcli.storage.core.device.setconfig($false,$RDM,$true)
$esxcli.storage.core.device.list($rdm)
}
}