VMware Cloud Community
davdjross
Contributor
Contributor
Jump to solution

Match each datastore to its Lun ID then list VMs in each datastore

Hi,

    Can anyone help? I'm looking to create a report which will show each datastores lunID and datastore name, list the VMs belonging to those datastores and the name of the VCenter at the top of the report. I've tried a few combinations however getting the lunID has proved the most difficult. Any help gratefully appreciated.

Thanks

0 Kudos
1 Solution

Accepted Solutions
ccalvetTCC
Enthusiast
Enthusiast
Jump to solution

If you are using only LUNs an easy way to get the canonical name is:

get-datastore | Select-Object Name,@{Name="CanonicalName";expression={$_.extensiondata.info.vmfs.extent.diskname}}

I do not understand your requirement regarding the vCenter Name, but for everything else

get-datastore | foreach {($MyDatastore = $_)} | get-vm | Select-Object @{Name="Datastore";expression={$MyDatastore}},@{Name="CanonicalName";expression={$MyDatastore.extensiondata.info.vmfs.extent.diskname}},Name

Blog: http://thecrazyconsultant.com/ | Twitter: @ccalvetTCC

View solution in original post

0 Kudos
3 Replies
ccalvetTCC
Enthusiast
Enthusiast
Jump to solution

If you are using only LUNs an easy way to get the canonical name is:

get-datastore | Select-Object Name,@{Name="CanonicalName";expression={$_.extensiondata.info.vmfs.extent.diskname}}

I do not understand your requirement regarding the vCenter Name, but for everything else

get-datastore | foreach {($MyDatastore = $_)} | get-vm | Select-Object @{Name="Datastore";expression={$MyDatastore}},@{Name="CanonicalName";expression={$MyDatastore.extensiondata.info.vmfs.extent.diskname}},Name

Blog: http://thecrazyconsultant.com/ | Twitter: @ccalvetTCC
0 Kudos
sajal1
Hot Shot
Hot Shot
Jump to solution

Hi,

Can you please try the following? Runs fine in my Lab environment. Due to non availability of resources could not test extensively.

$datastores = Get-Datastore

$details = @()

$ErrorActionPreference = 'SilentlyContinue'

Foreach ($datastore in $datastores) {

    $data = New-Object -TypeName PSObject | Select Name, LunId, VMs

    $data.LunId =  (Get-ScsiLun -Datastore $datastore | Select -Unique).CanonicalName.Split('.')[1]

    $data.Name = $datastore.Name

    $data.VMs = (Get-VM -Datastore $datastore.Name).Name

    $details += $data

}

$details

Please let me know if you face any issues and I can fine tune

0 Kudos
davdjross
Contributor
Contributor
Jump to solution

‌THanks. I'll try this early Tuesday morning and let you know How it goes.

0 Kudos