DaHess_DNVGL
Contributor
Contributor

Get Virtual Disk SCSI-IDs

Hi,

Is there an easy way to get the SCSI-ID of a VMs Virtual Disks displayed in a Get-VM | Get-Harddisk output?

So far I could not find a way to retrieve the SCSI-IDs for the Virtual Disks in the same output as "Get-HardDisk".

It is simply not available, but it my opinion it should be there out of the box.

I managed to get the SCSI-IDs of the Virtual Disks by importing this function and then run the command Get-VM <MyVM>  | Get-VMDisk,

but I don't like the output really and I would rather like to have an Object "SCSI-ID" in the "Get-Harddisk" cmdlet output.

25 Replies
LucD
Leadership
Leadership

I suspect that Excel "guesses" that the string is to be interpreted as a time (hh:mm).

You could replace the ':' by something else.


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

0 Kudos
SergOO
Enthusiast
Enthusiast

$vmservera1 = Read-Host "Enter VM"

Get-VM -Name $vmservera1  | Get-HardDisk |

Select @{N='VM';E={$_.Parent.Name}},

  Name, DiskType, Filename, ScsiCanonicalName, @{N="CapacityGB"; E={'{0:N0}' -f (($_.CapacityKB)/1024/1024)}},

   @{N='SCSIid';E={

   $hd = $_

   $ctrl = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $hd.ExtensionData.ControllerKey}

   "$($ctrl.BusNumber):$($_.ExtensionData.UnitNumber)"

   }} | ft -AutoSize -Wrap

vms.png

0 Kudos
bikashyadav
Contributor
Contributor

Hi LucD,

How do i run this script for a single VM. I mean i make a get-vmdisk.ps1 but how can i put .\get-vmdisk.ps1 VMName to get info on the VMname.

Thanks

Bikash

0 Kudos
LucD
Leadership
Leadership

You could do

param([string]$VMName)

Get-VM -Name $VMName  | Get-HardDisk |

Select @{N='VM';E={$_.Parent.Name}},

  Name, DiskType, Filename, ScsiCanonicalName, @{N="CapacityGB"; E={'{0:N0}' -f (($_.CapacityKB)/1024/1024)}},

   @{N='SCSIid';E={

   $hd = $_

   $ctrl = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $hd.ExtensionData.ControllerKey}

   "$($ctrl.BusNumber):$($_.ExtensionData.UnitNumber)"

   }} | ft -AutoSize -Wrap

Now call it with

.\get-vmdisk.ps1 -VMName MyV


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

memunoz
Contributor
Contributor

LucD great script/command, but I try execute on a VMWare cluster with ESXi 6.7 U3 installed on hosts, then  the information about SCSI Ctlr not shown, the results are like the next:

                                                                                                                                  
VMNameSCSIid
 Hard disk 1:0
 Hard disk 2:1
 Hard disk 3:2
 Hard disk 4:3
 Hard disk 5:4
 Hard disk 6:5

 

Where the column not contain information about the SCSI Controller, can you help me with the correction to get information complete about the scsi ctlr and VM Name ? Thanks in advance!!!

0 Kudos
Ankushsethi
Enthusiast
Enthusiast

try with this

param([string]$ClusterName

$report=@()

$vms=get-cluster $clustername|get-vmhost|get-vm

foreach($vm in $vms)

{

$report+=@(get-vm $vm|Get-HardDisk|Select Name,DiskType, Filename, ScsiCanonicalName,

@{N='VM';E={$_.Parent.Name}},

    @{N="CapacityGB"; E={'{0:N0}' -f (($_.CapacityKB)/1024/1024)}},

   @{N='SCSIid';E={

   $hd = $_

   $ctrl = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $hd.ExtensionData.ControllerKey}

   "$($ctrl.BusNumber):$($_.ExtensionData.UnitNumber)"

   }} )

}

$report|ft -autosize

0 Kudos