6 Replies Latest reply on Aug 19, 2019 8:54 AM by mikeydfpni

    extract lun ids from esxi 6.5

    mikeydfpni Lurker

      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