Jac_
Contributor
Contributor

Optimizing LUN UUID Report

Hi,

I am trying to put together a report that pulls information per datastore to include the UUID of the LUN as well as some other available properties, however the report is taking hours to run (It's been running over 24 hours on a single vCenter).

I would appreciate any ideas or recommendations to optimize the snippet below to decrease the runtime.

Thanks in advance for any help

#Get All Datastores
Write-Host "Getting datastores..."
$Datastores = Get-Datastore

Write-Host "Getting LUN information..."
$Report = Foreach ($Datastore in $Datastores) {
    $Datastore | Get-ScsiLun | Sort-Object VMhost | Select-Object `
        @{n='Region';E={$Region}}, `
        @{n='vCenter';E={$Server.vCenter}}, `
        @{n='Datastore';E={$Datastore.Name}}, `
        VMHost, `
        CanonicalName, `
        CapacityGB, `
        Vendor, 
        Model,
        MultipathPolicy, `
        LunType, `
        IsLocal, `
        IsSsd,`
        @{n='LunID';E={(Get-ScsiLun -VmHost $_.VMHost -CanonicalName $_.CanonicalName).ExtensionData.Uuid}} `
    | Sort-Object -Property Datastore
}

$Report | Export-Csv -Path $VMResult -NoTypeInformation -Append

 

0 Kudos
3 Replies
LucD
Leadership
Leadership

Instead of Get-ScsiLun use the StorageDevice property of the ESXi node.
See for example Solved: Re: Find a datastore, canonical name and runtime h... - VMware Technology Network VMTN


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

0 Kudos
Jac_
Contributor
Contributor

Hi LucD,

Please could you advise how to get the LUN UUID via the StorageDevice property?

Thanks,

Jacob

0 Kudos
LucD
Leadership
Leadership

The ScsiLun object, from which the sample I pointed to gets the CanonicalName, also contains the UUID.
It's just a matter of retrieving those objects and using the properties


Get-Datastore -PipelineVariable ds |
where{$_.Type -eq 'VMFS'} |
ForEach-Object -Process {
  Get-VMHost -Datastore $ds -PipelineVariable esx |
  ForEach-Object -Process {
    $ds.ExtensionData.Info.Vmfs.Extent.DiskName |
    ForEach-Object -Process {
      $disk = $_
      $lun = $esx.ExtensionData.Config.StorageDevice.ScsiLun | where{$_.CanonicalName -eq $disk}
      $path = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | where{$_.Lun -eq $lun.Key}
      $disk | Select-Object -Property @{N = 'vCenter'; E = { ([uri]$ds.ExtensionData.Client.ServiceUrl).Host}},
        @{N='Datastore';E={$ds.Name}},
        @{N='VMHost';E={$esx.Name}},
        @{N='CanonicalName';E={$_}},
        @{N='CapacityGB';E={$ds.CapacityGB}},
        @{N='Vendor';E={$lun.Vendor}},
        @{N='Model';E={$lun.Model}},
        @{N='MultipathPolicy';E={$path.Policy.Policy}},
        @{N='LunType';E={$lun.DeviceType}},
        @{N='IsLocal';E={$lun.LocalDisk}},
        @{N='IsSsd';E={$lun.Ssd}},
        @{N='LunID';E={$lun.Uuid}}
    }
  }
}


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