VMware Cloud Community
BoomBoomB
Contributor
Contributor
Jump to solution

Getting LUN# on new datastore Add wizard with powercli

I need to script creating bunch of new datastores via powercli but I got stuck in one point

How do I get the LUN# that shows up when creating VMFS DS via Wizard in powercli:

I can get list of all available devices via

$stg = get-view $esx.ExtensionData.ConfigManager.DatastoreSystem

and

$stg.QueryAvailableDisksForVmfs($null)

but my naming convention required me to add the LUN# that shows up in  the add wizard to the datastore name, and I am stuck here

can I get that LUN# any where via powercli?

Tags (2)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try with this variation

$esx = Get-VMHost -Name MyEsx

$stg = get-view $esx.ExtensionData.ConfigManager.DatastoreSystem

$stg.QueryAvailableDisksForVmfs($null) |

Select DisplayName,@{N='LUN';E={

    $lun = $_

    $lunKey = $esx.ExtensionData.Config.StorageDevice.ScsiLun |

        where{$_.CanonicalName -eq $lun.CanonicalName} |

        select -ExpandProperty Key

    $esx.ExtensionData.Config.StorageDevice.ScsiTopology.Adapter.Target.Lun |

        where{$_.ScsiLun -eq $lunKey} |

        Select -ExpandProperty Lun |

        Sort-Object -Unique

}}


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

View solution in original post

7 Replies
LucD
Leadership
Leadership
Jump to solution

Does this work for you?

$esx = Get-VMHost -Name MyEsx

$stg = get-view $esx.ExtensionData.ConfigManager.DatastoreSystem

$stg.QueryAvailableDisksForVmfs($null) |

Select DisplayName,@{N='LUN';E={

    $lun = $_

    $lunKey = $esx.ExtensionData.Config.StorageDevice.ScsiLun |

        where{$_.CanonicalName -eq $lun.CanonicalName} |

        select -ExpandProperty Key

    $lunPath = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun |

        where{$_.Lun -eq $lunKey} |

        Select -ExpandProperty Path

    $lunPath.Name.Split('L')[1]

}}


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

Reply
0 Kudos
BoomBoomB
Contributor
Contributor
Jump to solution

this is the output I got from your script Luc

it is display name and more of descriptor output from extended property

DisplayName : EMC Fibre Channel Disk (naa.60000970000192603280533034314337)

LUN         : fc.2000000e1e0940df:2100000e1e0940df-fc.5000097208334000:50000972083341d1-naa.60000970000192603280533034314337

DisplayName : DGC Fibre Channel Disk (naa.600601600c304300271a1f598befb16b)

LUN         : fc.2000000e1e0940df:2100000e1e0940df-fc.50060160c7e01c6a:5006016047e41c6a-naa.600601600c304300271a1f598befb16b

DisplayName : EMC Fibre Channel Disk (naa.60000970000192603280533033364141)

LUN         : fc.2000000e1e0940fd:2100000e1e0940fd-fc.5000097208334000:50000972083341ed-naa.60000970000192603280533033364141

DisplayName : EMC Fibre Channel Disk (naa.60000970000192603280533033364146)

LUN         : fc.2000000e1e0940fd:2100000e1e0940fd-fc.5000097208334000:50000972083341ed-naa.60000970000192603280533033364146

DisplayName : EMC Fibre Channel Disk (naa.60000970000192603280533031443835)

LUN         : fc.2000000e1e0940df:2100000e1e0940df-fc.5000097208334000:50000972083341d1-naa.60000970000192603280533031443835

DisplayName : DGC Fibre Channel Disk (naa.6006016014f0350090b20e756bc3e411)

LUN         : fc.2000000e1e0940fd:2100000e1e0940fd-fc.50060160b660262a:500601603660262a-naa.6006016014f0350090b20e756bc3e411

DisplayName : DGC Fibre Channel Disk (naa.600601600c304300281a1f59a8372f1d)

LUN         : fc.2000000e1e0940df:2100000e1e0940df-fc.50060160c7e01c6a:5006016047e41c6a-naa.600601600c304300281a1f59a8372f1d

DisplayName : EMC Fibre Channel Disk (naa.60000970000192603280533033464244)

LUN         : fc.2000000e1e0940fd:2100000e1e0940fd-fc.5000097208334000:50000972083341ed-naa.60000970000192603280533033464244

DisplayName : DGC Fibre Channel Disk (naa.600601600c304300291a1f5942e06d5a)

LUN         : fc.2000000e1e0940df:2100000e1e0940df-fc.50060160c7e01c6a:5006016047e41c6a-naa.600601600c304300291a1f5942e06d5a

DisplayName : EMC Fibre Channel Disk (naa.60000970000192603280533031444130)

LUN         : fc.2000000e1e0940df:2100000e1e0940df-fc.5000097208334000:50000972083341d1-naa.60000970000192603280533031444130

DisplayName : EMC Fibre Channel Disk (naa.60000970000192603280533034314233)

LUN         : fc.2000000e1e0940df:2100000e1e0940df-fc.5000097208334000:50000972083341d1-naa.60000970000192603280533034314233

DisplayName : EMC Fibre Channel Disk (naa.60000970000192603280533034314238)

LUN         : fc.2000000e1e0940df:2100000e1e0940df-fc.5000097208334000:50000972083341d1-naa.60000970000192603280533034314238

DisplayName : DGC Fibre Channel Disk (naa.600601600c304300281a1f592b7d2998)

LUN         : fc.2000000e1e0940df:2100000e1e0940df-fc.50060160c7e01c6a:5006016047e41c6a-naa.600601600c304300281a1f592b7d2998

DisplayName : EMC Fibre Channel Disk (naa.60000970000192603280533034314332)

LUN         : fc.2000000e1e0940df:2100000e1e0940df-fc.5000097208334000:50000972083341d1-naa.60000970000192603280533034314332

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

What does this show (I only need a couple of LUNs).

Get-ScsiLun -LunType disk -VmHost $esx | fl


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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try with this variation

$esx = Get-VMHost -Name MyEsx

$stg = get-view $esx.ExtensionData.ConfigManager.DatastoreSystem

$stg.QueryAvailableDisksForVmfs($null) |

Select DisplayName,@{N='LUN';E={

    $lun = $_

    $lunKey = $esx.ExtensionData.Config.StorageDevice.ScsiLun |

        where{$_.CanonicalName -eq $lun.CanonicalName} |

        select -ExpandProperty Key

    $esx.ExtensionData.Config.StorageDevice.ScsiTopology.Adapter.Target.Lun |

        where{$_.ScsiLun -eq $lunKey} |

        Select -ExpandProperty Lun |

        Sort-Object -Unique

}}


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

BoomBoomB
Contributor
Contributor
Jump to solution

that was it.  it provided the LUN ID that I need to incorporate

thank you so much.

output:

DisplayName : EMC Fibre Channel Disk (naa.60000970000192603280533034314337)

LUN         : 109

DisplayName : EMC Fibre Channel Disk (naa.60000970000192603280533033364141)

LUN         : 34

DisplayName : EMC Fibre Channel Disk (naa.60000970000192603280533033364146)

LUN         : 35

Reply
0 Kudos
tmack8080
Contributor
Contributor
Jump to solution

Why is is so dam difficult to create a datastore with PowerCLI? least VMware could do is add the LUN as an object property so it can be easily referenced. Geezzz
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I think I see what you mean, and it can be easily solved imho.

Just create an alias, named CanonicalName, for the Path parameter on the New-Datastore cmdlet, and then define the parameter as accepting pipeline input, with the ValueByProperty attribute.

Then you could do Get-ScsiLun | New-Datastore (I'm simplifying :smileygrin:).

But the good news is, you can do that yourself, by creating a Proxy Command for the New-Datastore cmdlet.


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

Reply
0 Kudos