VMware Cloud Community
jessem
Enthusiast
Enthusiast
Jump to solution

SAN Information Needed

Hey everyone,

I need help outputting the following information in a csv.

Hostname,

Datastore Name

LUN/Canonical Name

Path State (Active/Dead)

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Change the 1st line

$output = foreach ($esxi in Get-VMHost | Sort Name)


into


$output = foreach ($esxi in GetCluster -Name "os 01" | Get-VMHost | Sort Name)


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

View solution in original post

0 Kudos
9 Replies
ssbkang
Enthusiast
Enthusiast
Jump to solution

Hi,

The following script should do, modify the bold and italic line to change the output path:

$output = foreach ($esxi in Get-VMHost | Sort Name)

{

    $esxcli = Get-EsxCli -VMHost $esxi

    $datastore_info = $esxi.ExtensionData.Config.FileSystemVolume.MountInfo | %{$_.Volume} | Where-Object { if ($_.Name) { $_ } }

    foreach ($datastore in $datastore_info | Sort Name)

    {

        $adapter_information = $esxcli.storage.core.path.list() | Where-Object {$_.Device -match ($datastore.Extent | %{$_.DiskName})}      

        $datastore | Select-Object @{N="ESXi";E={$esxi.Name}}, @{N="Datastore";E={$datastore.Name}}, @{N="Canonical Name";E={$datastore.Extent | %{$_.DiskName}}}, @{N="RunTimeName";E={[string]::Join(",", ($adapter_information | %{$_.RunTimeName}))}}, @{N="State";E={[string]::Join(",", ($adapter_information | %{$_.State}))}}

    }

}

$output | Export-Csv "C:\Location\output.csv"

Sample Output:

ESXi           : abcd.test.com                                                                                                                                                                 

Datastore      : test_volume                                                                                                                                                                           

Canonical Name : naa.600xxxxxxxxxxxxxxxxxx                                                                                                                                                       

RunTimeName    : vmhba1:C0:T0:L0,vmhba1:C0:T0:L1                                                                                                                                                            

State          : active,active

Hope this helps,

Steven.

LucD
Leadership
Leadership
Jump to solution

Nice script.

If I might suggest the following small change.

This version will only show VMFS volumes and take into account that there might be multi-extent VMFS datastores.

$output = foreach ($esxi in Get-VMHost | Sort Name)
{
 
$esxcli = Get-EsxCli -VMHost $esxi
 
$datastore_info = $esxi.ExtensionData.Config.FileSystemVolume.MountInfo | %{$_.Volume} | Where-Object { if ($_.Name) { $_ } }
 
foreach ($datastore in $datastore_info | Sort Name)
  {
   
$esxcli.storage.vmfs.extent.list() | where {$_.VolumeName -eq $datastore.Name} | %{
     
$adapter_information = $esxcli.storage.core.path.list($_.DeviceName)
     
$datastore | Select-Object @{N="ESXi";E={$esxi.Name}},
     
@{N="Datastore";E={$datastore.Name}},
     
@{N="Canonical Name";E={$datastore.Extent | %{$_.DiskName}}},
     
@{N="RunTimeName";E={[string]::Join(",", ($adapter_information | %{$_.RunTimeName}))}},
     
@{N="State";E={[string]::Join(",", ($adapter_information | %{$_.State}))}}
    }
  }
}
$output | Export-Csv "C:\output.csv" -UseCulture


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

ssbkang
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

Thanks for the suggestion, that looks great Smiley Happy

Regards,

Steven.

0 Kudos
jessem
Enthusiast
Enthusiast
Jump to solution

Thanks guys.  One thing I forget to mention.  Where in the script can I fit the name of the Cluster I want it to target? 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

At the top of the ForEach loop, inside the code block you can insert a line like this

$cluster = Get-Cluster -VMHost $esxi

Then add a calculated property on the Select cmdlet

@(N="Cluster";E={$cluster.Name}}


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

0 Kudos
jessem
Enthusiast
Enthusiast
Jump to solution

Hello, that will work.  However, I guess maybe I'm confusing things.  Were in the code, can I actually specify the actual name of the cluster myself?

get-cluster "os 01"

and then have that output to the csv

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Change the 1st line

$output = foreach ($esxi in Get-VMHost | Sort Name)


into


$output = foreach ($esxi in GetCluster -Name "os 01" | Get-VMHost | Sort Name)


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

0 Kudos
jessem
Enthusiast
Enthusiast
Jump to solution

Thanks, that didn't work at first, simple correct...appreciate the help like always!

$output = foreach ($esxi in Get-Cluster -Name "os 01" | Get-VMHost | Sort Name)

0 Kudos
ssbkang
Enthusiast
Enthusiast
Jump to solution

Thanks for replying LucD :smileygrin:

0 Kudos