Hey everyone,
I need help outputting the following information in a csv.
Hostname,
Datastore Name
LUN/Canonical Name
Path State (Active/Dead)
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
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.
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
Hi LucD,
Thanks for the suggestion, that looks great
Regards,
Steven.
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?
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
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
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
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)
Thanks for replying LucD :smileygrin: