VMware Cloud Community
pscheri
Enthusiast
Enthusiast
Jump to solution

Help displaying datastore information

Hi, i am trying to format a table with information from various commands, and I can not figure out how to do it.

Basically I want the table to have the following information:

ESX Host - DatastoreName - CanonicalName - CapacityMB - MultipathPolicy

The problem is that the get-scsilun cli only gets me the canonical, capacity and multipath, but I want to add the other information from get-datastore and get-vmhost

The command i am ussing is:

get-vmhost | Get-ScsiLun | where-object {$_.Vendor -eq "EmC" -and $_.LunType -eq "disk"} | Format-Table -property CanonicalName,CapacityMB,MultipathPolicy -auto | Out-String -Width 120

Any idea of how to do this??

Thanks in advance!

Pablo.-

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$report =@()

foreach($esx in get-vmhost){
    foreach($lun in (Get-ScsiLun -VmHost $esx -LunType disk | where-object {$_.Vendor -eq "EMC"})){
        foreach($ds in (Get-Datastore -VMHost $esx)){
            $ds.ExtensionData.Info.Vmfs.Extent | %{
                if($_.diskName -eq $lun.CanonicalName){
                    $row = "" | Select Host,DS,CanonicalName,CapacityMB,MultiPathPolicy
                    $row.Host = $esx.Name
                    $row.DS = $ds.Name
                    $row.CanonicalName = $lun.CanonicalName
                    $row.CapacityMB = $lun.CapacityMB
                    $row.MultiPathPolicy = $lun.MultipathPolicy
                    $report += $row
                }             }         }     }        }

$report | ft -AutoSize

The link between the datastore and the LUN is done by comparing the LUN's canonicalname with each canonicalname of the disk extents of the datastores.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$report =@()

foreach($esx in get-vmhost){
    foreach($lun in (Get-ScsiLun -VmHost $esx -LunType disk | where-object {$_.Vendor -eq "EMC"})){
        foreach($ds in (Get-Datastore -VMHost $esx)){
            $ds.ExtensionData.Info.Vmfs.Extent | %{
                if($_.diskName -eq $lun.CanonicalName){
                    $row = "" | Select Host,DS,CanonicalName,CapacityMB,MultiPathPolicy
                    $row.Host = $esx.Name
                    $row.DS = $ds.Name
                    $row.CanonicalName = $lun.CanonicalName
                    $row.CapacityMB = $lun.CapacityMB
                    $row.MultiPathPolicy = $lun.MultipathPolicy
                    $report += $row
                }             }         }     }        }

$report | ft -AutoSize

The link between the datastore and the LUN is done by comparing the LUN's canonicalname with each canonicalname of the disk extents of the datastores.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
pscheri
Enthusiast
Enthusiast
Jump to solution

thank you so much! exactly what i wanted to do!

0 Kudos
vmhyperv
Contributor
Contributor
Jump to solution

LucD,

  Can we extract the output to CSV format as the output shows that

WARNING: 2 columns do not fit into the display and were removed.

Kindly help.

Thanks

Kumar

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, replace the last line with something like this

$report | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
vmhyperv
Contributor
Contributor
Jump to solution

$report =@()

foreach($esx in get-vmhost){
    foreach($lun in (Get-ScsiLun -VmHost $esx -LunType disk | where-object {$_.Vendor -eq "EMC"})){
        foreach($ds in (Get-Datastore -VMHost $esx)){
            $ds.ExtensionData.Info.Vmfs.Extent | %{
                if($_.diskName -eq $lun.CanonicalName){
                    $row = "" | Select Host,DS,CanonicalName,CapacityMB,MultiPathPolicy
                    $row.Host = $esx.Name
                    $row.DS = $ds.Name
                    $row.CanonicalName = $lun.CanonicalName
                    $row.CapacityMB = $lun.CapacityMB
                    $row.MultiPathPolicy = $lun.MultipathPolicy
                    $report += $row                }
            }
        }
    }       
}$report | Export-Csv "C:\dsreport.csv" -NoTypeInformation -UseCulture

Got it and can we convert ot  HTML the output and how  much DS free space left.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try this version

$report =@()

foreach($esx in get-vmhost){
    foreach($lun in (Get-ScsiLun -VmHost $esx -LunType disk | where-object {$_.Vendor -eq "EMC"})){
        foreach($ds in (Get-Datastore -VMHost $esx)){
            $ds.ExtensionData.Info.Vmfs.Extent | %{
                if($_.diskName -eq $lun.CanonicalName){
                    $row = "" | Select Host,DS,CanonicalName,CapacityMB,FreeSpaceMB,MultiPathPolicy
                    $row.Host = $esx.Name
                    $row.DS = $ds.Name
                    $row.CanonicalName = $lun.CanonicalName
                    $row.CapacityMB = $lun.CapacityMB
                    $row.FreeSpaceMB = $ds.FreeSpaceMB
                    $row.MultiPathPolicy = $lun.MultipathPolicy
                    $report += $row
                }             }         }     }        }
$report | ConvertTo-Html | Out-File "C:\report.html"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
vmhyperv
Contributor
Contributor
Jump to solution

Thanks LucD  it worked and i appreciate you.

0 Kudos
vmhyperv
Contributor
Contributor
Jump to solution

LucD,

  In Test Environmetn its working for me in Prod its throwing  error

[vSphere PowerCLI] C:\tmp> .\Display-ds-info.ps1
Get-VMHost : 5/26/2011 3:40:55 AM    Get-VMHost        Server vc1 not
connected.
At C:\tmp\Display-ds-info.ps1:3 char:27
+ foreach($esx in get-vmhost <<<< ){
    + CategoryInfo          : InvalidArgument: (:) [Get-VMHost], ViServerConne
   ctionException
    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryVerifyIsConn
   ected_NotConnected,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost

Any correction required in script.I have attached the script.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

It looks as if your connection to the vCenter is not active.

You can see the connections with

$defaultVIServers


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
AlbertWT
Virtuoso
Virtuoso
Jump to solution

Yes LucD is the master !

I got the PowerCLi book next to me and I regard it as the PowerCLI Bible 🙂

/* Please feel free to provide any comments or input you may have. */
0 Kudos