VMware Cloud Community
mikeydfpni
Contributor
Contributor
Jump to solution

extract lun ids from esxi 6.5

Hi

Looking for a bit of help with a script I have. This script works with esxi 5.5 but not 6.5. Can anyone help me with why the Lun_ID is not showing in 6.5.

$report = @()

$VMs = @("")

Foreach ($VM in $VMs){

$LUN = ""

$VmView = Get-View -ViewType VirtualMachine -Filter @{"Name" = $VM}

foreach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "SCSI Controller"})) {

foreach ($VirtualDiskDevice in ($VMView.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key})) {

if(($VirtualDiskDevice.Backing.CompatibilityMode -eq "physicalMode") -or ($VirtualDiskDevice.Backing.CompatibilityMode -eq "virtualMode"))

{

                        $VMinfo = Get-VM $VM

$LUN = Get-Scsilun ($VMinfo | Get-Harddisk -Name ($VirtualDiskDevice.DeviceInfo.Label)).ScsiCanonicalName -VmHost ($VMinfo).VMHost

$line = "" | Select 'VMName', 'VMHost', 'HDDeviceName', 'HDName', 'HDFileName', 'HDMode', 'HDSize(GB)','LUN_ID', 'CanonicalName', 'SCSI_ID'

$line.'VMName' = $VMinfo.name

$line.'VMHost' = get-view $vmview.runtime.host | select -ExpandProperty name

$line.'HDDeviceName'  = $VirtualDiskDevice.Backing.DeviceName

$line.'HDName'      = $VirtualDiskDevice.DeviceInfo.Label

$line.'HDFileName'      = $VirtualDiskDevice.Backing.FileName

$line.'HDMode' = $VirtualDiskDevice.Backing.CompatibilityMode

$line.'HDSize(GB)'  = ($VirtualDiskDevice.CapacityInKB * 1KB / 1GB)

$line.'LUN_ID' = $LUN.RuntimeName.Substring($LUN.RuntimeName.LastIndexOf("L")+1)

$line.'CanonicalName' = ($VMinfo | Get-Harddisk -Name ($VirtualDiskDevice.DeviceInfo.Label)).ScsiCanonicalName

$line.'SCSI_ID'       = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"

$Report += $line

}

}

}

}

$report

Many Thanks

Mikey

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The latest (11.3.0), will give you all bug fixes, performance improvements and new features.

Note that the later versions are installed from the PowerShell Gallery with Install-Module.

See Welcome PowerCLI to the PowerShell Gallery – Install Process Updates for details.

---------------------------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

View solution in original post

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Which PowerCLI version are you using?


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

Reply
0 Kudos
mikeydfpni
Contributor
Contributor
Jump to solution

I am using 5.8 Release 1.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That's a very old version.
Any reason why you are still on that version?


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

Reply
0 Kudos
mikeydfpni
Contributor
Contributor
Jump to solution

No reason, just never upgraded it. what version would you recommend?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The latest (11.3.0), will give you all bug fixes, performance improvements and new features.

Note that the later versions are installed from the PowerShell Gallery with Install-Module.

See Welcome PowerCLI to the PowerShell Gallery – Install Process Updates for details.

---------------------------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

Reply
0 Kudos
mikeydfpni
Contributor
Contributor
Jump to solution

Hi LucD

Many Thanks

Updating my PowerCLI has solved my issue.

Reply
0 Kudos