Hi All,
I need to produce a report of all datastores that will include the datstore name, capacitygb, freespacegb and NAA. This is what I came up with but it just runs forever. Any suggestions?
$datastores = Get-Datastore |
Where-Object {$_.ExtensionData.Info.GetType().Name -eq "VmfsDatastoreInfo"}
$report=@()
Foreach ($d in $datastores){
$temp = New-Object -TypeName PSObject -Property @{
Name = $d.Name
CapacityGB = $d.CapacityGB
FreeSpaceGB = $d.FreeSpaceGB
NAA = Get-Scsilun -Datastore $d | select canonicalname
}
$report+=$temp
}
$report | Export-Csv h:\Documents\AllScripts\test3.csv
The Get-ScsiLun cmdlet can take a lot of time, it's not the fastest cmdlet around.
If you have only 1 LUN in a datastore, you can do something like this to get the same result
Get-Datastore | where {$_.Type -eq "VMFS"} |
Select Name,CapacityGB,FreeSpaceGB,
@{N="NAA";E={$_.ExtensionData.Info.Vmfs.Extent | Select -ExpandProperty DiskName}} |
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
If there can be more than 1 LUN per datastore, the script needs a small change.
Get-Datastore | where {$_.Type -eq "VMFS"} |
Select Name,CapacityGB,FreeSpaceGB,
@{N="NAA";E={[string]::Join(',',($_.ExtensionData.Info.Vmfs.Extent | Select -ExpandProperty DiskName)}} |
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The Get-ScsiLun cmdlet can take a lot of time, it's not the fastest cmdlet around.
If you have only 1 LUN in a datastore, you can do something like this to get the same result
Get-Datastore | where {$_.Type -eq "VMFS"} |
Select Name,CapacityGB,FreeSpaceGB,
@{N="NAA";E={$_.ExtensionData.Info.Vmfs.Extent | Select -ExpandProperty DiskName}} |
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
If there can be more than 1 LUN per datastore, the script needs a small change.
Get-Datastore | where {$_.Type -eq "VMFS"} |
Select Name,CapacityGB,FreeSpaceGB,
@{N="NAA";E={[string]::Join(',',($_.ExtensionData.Info.Vmfs.Extent | Select -ExpandProperty DiskName)}} |
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are the best Luc!! I had something like that in another attempt, but I didnt have the -expandproperty. Thanks so much!
