VMware Cloud Community
bvi1006
Enthusiast
Enthusiast

Get datastores and lunuuid into columns for all hosts

Hi,

I have tried to modify a script I found on the web, but it's a bit too complicated for me to get what I am looking for. I am tryng to output all datastore names and lunuids for each host. We have some discrepencies in our environment. I have a report which shows the lun uuids but I need to know what the datastore name is. Here is my attempt (it's ugly) at getting this, would someone please take a look and see what is wrong? I am only getting the lun uuid for one host, repetitively. Thanks in advance!

$vmhosts = Get-VMHost
$report = @()
Foreach ($vmhost in $vmhosts)
{
    $ds = Get-View (Get-View (Get-VMHost -Name $vmhost).ID).ConfigManager.StorageSystem
    foreach ($vol in $ds.FileSystemVolumeInfo.MountInfo) {
        if ($vol.Volume.Name -eq $dsname) {
            $Details = " " |Select-Object volname, voluuid, lunid, uuid
            $Details.volname = $vol.Volume.volName
            $Details.voluuid = $vol.Volume.volUuid
            foreach ($volid in $vol.Volume.Extent) {
                foreach ($lun in $ds.StorageDeviceInfo.MultipathInfo.Lun){
                    if ($lun.Id -eq $volid.DiskName) {
                        break
                    }
                }
            }
$Details.lunid = $lun.ID
        $mid = $lun.ID
        foreach ($id in $ds.StorageDeviceInfo.ScsiLun) {
            if ($id.CanonicalName -eq $mid) {
                $uuid = $id.Uuid
  $details.uuid = $id.Uuid
                               }
            }
        }
        }
        }
$report += $MyDetails
$report

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

Where do you populate $dsname ?

if ($vol.Volume.Name -eq $dsname) {


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

Reply
0 Kudos
bvi1006
Enthusiast
Enthusiast

Good catch Smiley Wink

This would have been populated by running the original script with that as a parameter. The original required virtual center, host, and datastore name.

Thanks

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

It is sometimes easier to write a new script than to debug an existing one. Smiley Wink

Is the output of the following script what you want? It gives you the name of the datastore and the corresponding Uuid.

Get-Datastore |
Select-Object -ExpandProperty ExtensionData |
Select-Object -ExpandProperty Info |
Where-Object {$_.GetType().Name -eq "VmfsDatastoreInfo"} |
Select-Object -ExpandProperty Vmfs |
Select-Object -Property Name,Uuid

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
bvi1006
Enthusiast
Enthusiast

Actually this only gives me the local vmfs volumes, I am looking for all datastores.. thx

Reply
0 Kudos