PowerCLI: Find detached LUNs on ESXi hosts.

Script to find detached LUNs.

$clusters = Get-Cluster | Sort-Object -Property Name

foreach ($cluster in $clusters) {
  Write-Host $cluster
  $esxi_hosts = $cluster | get-Vmhost -State Connected,Maintenance | Sort-Object -Property Name

  foreach ($esxi_host in $esxi_hosts) {
    Write-Host $esxi_host
    ($esxi_host | Get-ScsiLun | where {$_.ExtensionData.OperationalState -eq "off"}).CanonicalName
  }
}

Here (link) is the PowerCLI code by LucD to attach or detach disks.