Reply to Message

View discussion in a popup

Replying to:
BenLiebowitz
Expert
Expert

Need help with RDM script to set them to Perennially Reserved

So I found this script to set the RDMs to Perennially Reserved, however, we have probably 15-20 VMs with RDMs so doing this manually can be tough.  I'd like to be able to have PowerCLI build a list of all the RDMs. 

I tried to build a foreach loop around the existing one one to detect all the RDMs from the multiple VMs using:  Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select Parent but was unsuccessful. 

$vmName = "VMwithRDM"

$vm = Get-VM -Name $vmName

$rdm = Get-HardDisk -DiskType rawPhysical -Vm $vm

$vmhosts = Get-Cluster -VM $vm | Get-VMHost

foreach($esx in $vmhosts){

  $esxcli = Get-EsxCli -VMHost $esx

  Get-HardDisk -DiskType rawPhysical -Vm $vm | %{

    $esxcli.storage.core.device.list($rdm.ScsiCanonicalName) |

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

    $esxcli.storage.core.device.setconfig($false,$rdm.ScsiCanonicalName,$true)

    $esxcli.storage.core.device.list($rdm.ScsiCanonicalName) |

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

  }

}

Any help would be appreciated! 

Thanks,

Ben Liebowitz, VCP vExpert 2015, 2016, & 2017 If you found my post helpful, please mark it as helpful or answered to award points.