ganapa2000
Hot Shot
Hot Shot

How do I get Disk Vendor details in the output

Jump to solution

How do I get Disk Vendor details in the output. Please help.

$DiskInfo= @()
foreach ($VMview in Get-VM MyVM1 | Get-View){
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})) {
$VirtualDisk = "" | Select VMname, SCSIController, DiskName, SCSI_ID, DeviceName, DiskFile, DiskSize
$VirtualDisk.VMname = $VMview.Name
$VirtualDisk.SCSIController = $VirtualSCSIController.DeviceInfo.Label
$VirtualDisk.DiskName = $VirtualDiskDevice.DeviceInfo.Label
$VirtualDisk.SCSI_ID = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"
$VirtualDisk.DeviceName = $VirtualDiskDevice.Backing.DeviceName.Where{$_ -ne ''} | %{$_.Substring(22,24).ToUpper()}
$VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName
$VirtualDisk.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB
$DiskInfo += $VirtualDisk
}}}
$DiskInfo

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Something like this

$DiskInfo = @()
foreach ($VMview in Get-VM MyVM1 | Get-View) {
  foreach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | Where-Object { $_.DeviceInfo.Label -match "SCSI Controller" })) {
    foreach ($VirtualDiskDevice in ($VMView.Config.Hardware.Device | Where-Object { $_.ControllerKey -eq $VirtualSCSIController.Key })) {
      $VirtualDisk = "" | Select-Object VMname, SCSIController, DiskName, SCSI_ID, DeviceName, DiskFile, DiskSize,Vendor
      $VirtualDisk.VMname = $VMview.Name
      $VirtualDisk.SCSIController = $VirtualSCSIController.DeviceInfo.Label
      $VirtualDisk.DiskName = $VirtualDiskDevice.DeviceInfo.Label
      $VirtualDisk.SCSI_ID = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"
      $VirtualDisk.DeviceName = $VirtualDiskDevice.Backing.DeviceName.Where{ $_ -ne '' } | ForEach-Object { $_.Substring(22, 24).ToUpper() }
      $VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName
      $VirtualDisk.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB
      $esxcli = Get-EsxCli -VMHost (Get-View -Id $VMview.Runtime.Host -Property Name).Name -V2
      $ds = Get-View -Id $VirtualDiskDevice.Backing.Datastore
      $VirtualDisk.Vendor = $esxcli.storage.core.device.list.Invoke(@{device = $ds.Info.Vmfs.Extent[0].DiskName }).Vendor
      $DiskInfo += $VirtualDisk
    }
  }
}
$DiskInfo


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

View solution in original post

2 Replies
LucD
Leadership
Leadership

Something like this

$DiskInfo = @()
foreach ($VMview in Get-VM MyVM1 | Get-View) {
  foreach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | Where-Object { $_.DeviceInfo.Label -match "SCSI Controller" })) {
    foreach ($VirtualDiskDevice in ($VMView.Config.Hardware.Device | Where-Object { $_.ControllerKey -eq $VirtualSCSIController.Key })) {
      $VirtualDisk = "" | Select-Object VMname, SCSIController, DiskName, SCSI_ID, DeviceName, DiskFile, DiskSize,Vendor
      $VirtualDisk.VMname = $VMview.Name
      $VirtualDisk.SCSIController = $VirtualSCSIController.DeviceInfo.Label
      $VirtualDisk.DiskName = $VirtualDiskDevice.DeviceInfo.Label
      $VirtualDisk.SCSI_ID = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"
      $VirtualDisk.DeviceName = $VirtualDiskDevice.Backing.DeviceName.Where{ $_ -ne '' } | ForEach-Object { $_.Substring(22, 24).ToUpper() }
      $VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName
      $VirtualDisk.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB
      $esxcli = Get-EsxCli -VMHost (Get-View -Id $VMview.Runtime.Host -Property Name).Name -V2
      $ds = Get-View -Id $VirtualDiskDevice.Backing.Datastore
      $VirtualDisk.Vendor = $esxcli.storage.core.device.list.Invoke(@{device = $ds.Info.Vmfs.Extent[0].DiskName }).Vendor
      $DiskInfo += $VirtualDisk
    }
  }
}
$DiskInfo


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

ganapa2000
Hot Shot
Hot Shot

Thank you very much. that worked perfectly 🙂

0 Kudos