I have written the script below to get information for my datastore.. It all workks well but i cannot seem to pull back the LUN Ids.....??????? I looking for way to match the datstore with free space and LUN IDs
$datastores = Get-Datastore | Sort-Object Name
Create an array to hold the output
$myColCurrent = @()
Loop through datastores
ForEach ($store in $datastores)
{
Create a custom object and define its properties
$myObj = "" | Select-Object Name, CapacityGB, UsedGB, PercFree, Type, ID, Accessible
Set the values of each property
$myObj.Name = $store.Name
$myObj.CapacityGB = math::Round($store.capacityMB/1024,$digits)
$myObj.UsedGB = math::Round(($store.CapacityMB - $store.FreeSpaceMB)/1024,$digits)
$myObj.PercFree = math::Round(100*$store.FreeSpaceMB/$store.CapacityMB,$digits)
$myObj.Type = $store.Type
$myObj.ID = $store.Id
$myObj.Accessible = $store.Accessible
Add the object to the output array
$myColCurrent += $myObj
}
Export the output
$myColCurrent | ConvertTo-Html -title "Datastore Information" -body "<H2>Datastore Information.</H2>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
What exactly do you mean with LUN id ?
Do you mean the device ? Something like vmhb...
Have a look at my script in .
Is it one of those fields you want ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes the Device name .. vmhba1:0...
@LUCD, your script
$esxhost = <ESX-host>
$report = @()
$hss = Get-View (Get-View (Get-VMHost -Name $esxhost).ID).ConfigManager.StorageSystem
foreach($mount in $hss.FileSystemVolumeInfo.MountInfo){
if($mount.Volume.Type -eq "VMFS"){
foreach($ext in $mount.Volume.Extent){
foreach($lun in $hss.StorageDeviceInfo.MultipathInfo.Lun){
if($lun.Id -eq $ext.DiskName) {break}
}
foreach($path in $lun.Path){
$row = "" | select DSname, Pathname, PathState, PortWWN
$row.DSname = $mount.Volume.Name
$row.Pathname = $ext.DiskName
$row.PathState = $path.PathState
$row.PortWWN = ("{0:x}" -f $path.Transport.PortWorldWideName)
$report += $row
}
}
}
}
$report
Has what i want but i need to add it to the LUN section in the script attached for all host and not just one hosts.....?????
The next script will add the disk device for VMFS datastores and the path for NFS datastores to the report.
function Get-DSDevice($dsImpl) { $ds = Get-View -Id $dsImpl.Id $esx = Get-View $ds.Host[0].Key $hss = Get-View $esx.ConfigManager.StorageSystem foreach($mount in $hss.FileSystemVolumeInfo.MountInfo){ if($mount.volume.name -eq $ds.Info.Name){ switch($mount.Volume.Type){ "VMFS" { foreach($ext in $mount.Volume.Extent){ if($mount.volume.name -eq $ds.Info.Name){ $device =$ext.DiskName } } } "NFS" { $device = $mount.Volume.RemoteHost + ":" + $mount.Volume.RemotePath } } } } $device } $datastores = get-vmhost | Get-Datastore | Sort-Object Name $myColCurrent = @() foreach ($store in $datastores){ $myObj = "" | Select-Object Name, CapacityGB, UsedGB, PercFree, Type, ID, Accessible $myObj.Name = $store.Name $myObj.CapacityGB = "{0:n2}" -f ($store.capacityMB/1kb) $myObj.UsedGB = "{0:N2}" -f (($store.CapacityMB - $store.FreeSpaceMB)/1kb) $myObj.PercFree = "{0:N}" -f (100 * $store.FreeSpaceMB/$store.CapacityMB) $myObj.Type = $store.Type $temp = Get-View -Id $store.Id $myObj.ID = Get-DSDevice $store $myObj.Accessible = $store.Accessible $myColCurrent += $myObj } $myColCurrent | ` ConvertTo-Html -title "Datastore Information" -body "<H2>Datastore Information.</H2>" -head "<link rel='stylesheet' href='style.css' type='text/css'/>" | ` Out-File -Append "C:\report.html"
I also took the liberty of formatting the figures a bit.
Note that PS has some very nice constants, like 1KB, 1MB..., that you can use instead of the actual number of bytes to do the calculations.
If you want to use my script you could place it in a loop.
Something like this
$report = @() Get-VMHost | where {$_.State -eq "Connected"} | % { $hss = Get-View (Get-View $_.ID).ConfigManager.StorageSystem foreach($mount in $hss.FileSystemVolumeInfo.MountInfo){ if($mount.Volume.Type -eq "VMFS"){ foreach($ext in $mount.Volume.Extent){ foreach($lun in $hss.StorageDeviceInfo.MultipathInfo.Lun){ if($lun.Id -eq $ext.DiskName) {break} } foreach($path in $lun.Path){ $row = "" | select ESXname, DSname, Pathname, PathState, PortWWN $row.ESXname = $_.Name $row.DSname = $mount.Volume.Name $row.Pathname = $ext.DiskName $row.PathState = $path.PathState $row.PortWWN = ("{0:x}" -f $path.Transport.PortWorldWideName) $report += $row } } } } } $report
Note that I added a filter to just look at the ESX servers that are "connected".
With servers that are "disconnected" or "notresponding" the information we use in the report is not accessible.
I also added the ESX hostname to the report for completeness.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference