I am trying to create a report of Perennially Reserved RDMs. When I check the output I only get 1 entry in the CSV. I know that there are many more. I think it has to do with assigning $esxcli for Get-ESXCli. Thank you for your help. My code is below:
param(
[Parameter(Mandatory=$true)][string] $TargetCluster#,
#[management.automation.PSCredential] $RootCredentials = (Get-Credential)
)
# Retrieve list of Hosts in Target Cluster
$ESXHosts = Get-Cluster $TargetCluster | Get-VMHost | Select-Object Name #| % { Connect-VIServer $_ -Credential $RootCredentials | Out-Null }
#$ESXHosts | ft
# Find the ScsiCanonicalName for all RDM Disks attached to VMs in the Target Cluster
$RDMDisks = Get-VM -Location $TargetCluster | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select ScsiCanonicalName
# Retrieve and EsxCli instance for each ESX Host
foreach($ESXHost in $ESXHosts ) {
$esxcli = Get-EsxCli -VMHost($ESXHost.Name)
#$esxcli | ft
# And for each RDM Disk
foreach($RDMDisk in $RDMDisks) {
$RDMDisk | ft
# Collect naa LUN ID and Perennially Reserved value
$esxcli.storage.core.device.list($RDMDisk.ScsiCanonicalName)| Select-Object Device, IsPerenniallyReserved | Export-Csv -NoTypeInformation -Path "C:\Users\cBurnett\SkyDrive\vSphere CLI Scripts\Set-RDMReservations\get-rdmreservations.csv"
}
}
# Disconnect the connection objects created for the Target Cluster
#Disconnect-VIServer * -Confirm:$false | Out-Null