PowerCli script to pull LUN id of datastore of cluster

Add-PSSnapin Vmware.Vimautomation.Core
Connect-VIServer “name of vcenter”
$clusters = Get-Cluster
#$host_Cluster = $cluster | %{ Get-VMHost -Location $_ }
foreach($cluster in $clusters)
{
    $host_Cluster = Get-VMHost -Location $cluster
      
foreach($hostServer in $host_Cluster)
{
$esxcli = Get-EsxCli -VMHost $hostServer.Name
$data = $esxcli.storage.core.path.list()
$naa = $esxcli.storage.vmfs.extent.list()
#$data
#$naa
$report=@()
$naa | %{
$D = $_.DeviceName
$dataStore = $_.VolumeName
$ext = $_.ExtentNumber
        $data | %{
        if($_.Device -eq $D)
        {
           $row = "" | select DName, LUN, datastore, extent, Host, Cluster
            $row.Dname = $D
            $row.LUN = $_.LUN
            $row.datastore = $dataStore
            $row.Extent = $ext
            $row.Host = $hostServer.Name
            $row.Cluster = $cluster
        }
                }
           
$report += $row
}
$report | Export-csv -NoTypeInformation "C:\csv-files\datastore_inventory.cvs" -Append
}
}
Disconnect-VIServer -Server $global:DefaultVIServers -Force

No comments:

Post a Comment