Automation

 View Only
Expand all | Collapse all

Get Virtual Disk SCSI-IDs

  • 1.  Get Virtual Disk SCSI-IDs

    Posted Dec 13, 2017 06:18 PM

    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.



  • 2.  RE: Get Virtual Disk SCSI-IDs

    Posted Dec 13, 2017 07:02 PM

    One easy way is with a calculated property.

    Get-VM | Get-HardDisk |

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



  • 3.  RE: Get Virtual Disk SCSI-IDs

    Posted Dec 13, 2017 09:36 PM

    Hi Luke,

    thanks for your quick reply.

    That  comes close to what I was looking for, but it is still missing the Controller-ID.

    As an example, here the output for one of our Oracle RAC-Node VMs:

    PS P:\> Get-VM OSL2420 | Get-HardDisk | Select @{N='VM';E={$_.Parent.Name}},Name,@{N='SCSIid';E={$_.ExtensionData.UnitNumber}}

    VM      Name         SCSIid

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

    OSL2420 Hard disk 1       0

    OSL2420 Hard disk 2       1

    OSL2420 Hard disk 14      2

    OSL2420 Hard disk 18      3

    OSL2420 Hard disk 19      4

    OSL2420 Hard disk 20      5

    OSL2420 Hard disk 21      6

    OSL2420 Hard disk 15      0

    OSL2420 Hard disk 16      1

    OSL2420 Hard disk 17      2

    OSL2420 Hard disk 3       3

    OSL2420 Hard disk 4       4

    OSL2420 Hard disk 5       5

    OSL2420 Hard disk 22      6

    OSL2420 Hard disk 23      8

    OSL2420 Hard disk 24      9

    OSL2420 Hard disk 25     10

    OSL2420 Hard disk 6       0

    OSL2420 Hard disk 7       1

    OSL2420 Hard disk 8       2

    OSL2420 Hard disk 9       3

    OSL2420 Hard disk 10      4

    OSL2420 Hard disk 11      5

    OSL2420 Hard disk 12      0

    OSL2420 Hard disk 13      1

    The vital piece of information I am missing in the output is the complete SCSI-ID that shows the controller ID followed by the Disk-ID in the same form as it is shown in the VM-Settings Dialog in the vSphere-Client.

    The Disk-ID on its own is useless if you use more than one SCSI-Controller.

    Is there any chance to get that full SCSI-ID displayed?



  • 4.  RE: Get Virtual Disk SCSI-IDs

    Posted Dec 14, 2017 06:17 AM

    Ok, try like this

    Get-VM | Get-HardDisk -PipelineVariable hd |

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

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

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



  • 5.  RE: Get Virtual Disk SCSI-IDs

    Posted Dec 14, 2017 09:41 PM

    that didnt help either.

    The output leaves the SCSI-ID Column empty.:

    VM      Name         SCSIid
    --      ----         ------
    OSL2420 Hard disk 1
    OSL2420 Hard disk 2
    OSL2420 Hard disk 14
    OSL2420 Hard disk 18
    OSL2420 Hard disk 19
    OSL2420 Hard disk 20
    OSL2420 Hard disk 21
    OSL2420 Hard disk 15
    OSL2420 Hard disk 16
    OSL2420 Hard disk 17
    OSL2420 Hard disk 3
    OSL2420 Hard disk 4
    OSL2420 Hard disk 5
    OSL2420 Hard disk 22
    OSL2420 Hard disk 23
    OSL2420 Hard disk 24
    OSL2420 Hard disk 25
    OSL2420 Hard disk 6
    OSL2420 Hard disk 7
    OSL2420 Hard disk 8
    OSL2420 Hard disk 9
    OSL2420 Hard disk 10
    OSL2420 Hard disk 11
    OSL2420 Hard disk 12
    OSL2420 Hard disk 13



  • 6.  RE: Get Virtual Disk SCSI-IDs

    Posted Dec 15, 2017 05:35 AM

    Which PowerShell version are you using?

    Do a $PSVersionTable.

    The Pipeline variable I used was introduced in PS v4



  • 7.  RE: Get Virtual Disk SCSI-IDs

    Posted Dec 15, 2017 11:24 AM

    Hi Luke,

    PS P:\> $PSVersionTable.PSVersion

    Major  Minor  Build  Revision

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

    5      1      15063  726

    PowerCLI Version

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

       VMware PowerCLI 6.5.1 build 5377412

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

    Component Versions

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

       VMware Cis Core PowerCLI Component 6.5 build 6983166

       VMware VimAutomation Core PowerCLI Component 6.5 build 6234650



  • 8.  RE: Get Virtual Disk SCSI-IDs

    Posted Dec 15, 2017 11:36 AM

    Strange, that is exactly the same as I have.

    And what happens when we leave out the pipelinevariable?

    Get-VM | Get-HardDisk |

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

        Name,

        @{N='SCSIid';E={

            $hd = $_

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

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

         }}



  • 9.  RE: Get Virtual Disk SCSI-IDs

    Posted Dec 15, 2017 11:43 AM

    Hey Luke,

    this time the output looks much better. Thank you very much. :smileyhappy:

    VM      Name         SCSIid

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

    OSL2420 Hard disk 1  0:0

    OSL2420 Hard disk 2  0:1

    OSL2420 Hard disk 14 0:2

    OSL2420 Hard disk 18 0:3

    OSL2420 Hard disk 19 0:4

    OSL2420 Hard disk 20 0:5

    OSL2420 Hard disk 21 0:6

    OSL2420 Hard disk 15 1:0

    OSL2420 Hard disk 16 1:1

    OSL2420 Hard disk 17 1:2

    OSL2420 Hard disk 3  1:3

    OSL2420 Hard disk 4  1:4

    OSL2420 Hard disk 5  1:5

    OSL2420 Hard disk 22 1:6

    OSL2420 Hard disk 23 1:8

    OSL2420 Hard disk 24 1:9

    OSL2420 Hard disk 25 1:10

    OSL2420 Hard disk 6  2:0

    OSL2420 Hard disk 7  2:1

    OSL2420 Hard disk 8  2:2

    OSL2420 Hard disk 9  2:3

    OSL2420 Hard disk 10 2:4

    OSL2420 Hard disk 11 2:5

    OSL2420 Hard disk 12 3:0

    OSL2420 Hard disk 13 3:1



  • 10.  RE: Get Virtual Disk SCSI-IDs

    Posted Jan 10, 2019 01:42 AM
    Hi LucD, this helps pretty much... how can you add another field like each VMDK path/location?


  • 11.  RE: Get Virtual Disk SCSI-IDs

    Posted Jan 10, 2019 06:11 AM

    Try like this

    Get-VM | Get-HardDisk |

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

      Name, Filename,

       @{N='SCSIid';E={

       $hd = $_

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

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

       }}



  • 12.  RE: Get Virtual Disk SCSI-IDs

    Posted May 21, 2020 01:31 AM

    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!!!



  • 13.  RE: Get Virtual Disk SCSI-IDs

    Posted Jun 09, 2020 05:06 PM

    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



  • 14.  RE: Get Virtual Disk SCSI-IDs

    Posted Jul 10, 2019 03:58 AM

    Hi luke,

    Is there a way to get the VMdks for virtual machine 

    Something like the listed using Orchestrator (vRO)

    VMName | VMdk | SCSI ID | 



  • 15.  RE: Get Virtual Disk SCSI-IDs

    Posted Jul 10, 2019 06:41 AM

    Isn't that what the script is showing?
    Or do you mean something else?
    Perhaps a sample of the output you mention would be helpful.



  • 16.  RE: Get Virtual Disk SCSI-IDs

    Posted Jan 18, 2019 09:05 AM

    Hi Luke,

    this small script is very helpful to me as well but I wasn't able to extend it so far to get additional information.

    Is it possible to get additional information like the VM UUID, VMDK UUID, SCSI Controller number and if possible the VMDK size visible in the WebClient beside the other output?

    Thank you very much.



  • 17.  RE: Get Virtual Disk SCSI-IDs

    Posted Jan 18, 2019 09:21 AM

    Try like this

    Get-VM | Get-HardDisk |

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

      @{N='VM Uuid';E={$_.Parent.ExtensionData.Config.Uuid}},

      Name,

      Filename,

      CapacityGB,

      @{N='VMDK Uuid';E={$_.ExtensionData.Backing.Uuid}},

       @{N='SCSIid';E={

       $hd = $_

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

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

       }},

       @{N='Controller#';E={(Get-ScsiController -HardDisk $_).UnitNumber}}



  • 18.  RE: Get Virtual Disk SCSI-IDs

    Posted Jan 18, 2019 09:45 AM

    Hi Luke,

    thanks for the quick reply.

    The output is exactly what I need.

    I get the output

    VM          :

    VM Uuid     : 421d5e48-a184-a4e4-f107-ef89cead9b77

    Name        : Hard disk 2

    Filename    :

    CapacityGB  : 60

    VMDK Uuid   : 6000C293-dd64-b578-273c-3fdc6ef9ec98

    SCSIid      : 0:1

    Controller# : 3

    Is it possible to get the output side by side like VM, VM UUID, .... and to expport it to a CSV file?



  • 19.  RE: Get Virtual Disk SCSI-IDs

    Posted Jan 18, 2019 09:49 AM

    That list format is driven by the size of your screen.
    To export to a CSV, just pipe the result to Export-Csv

    Get-VM | Get-HardDisk |

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

    @{N = 'VM Uuid'; E = {$_.Parent.ExtensionData.Config.Uuid}},

    Name,

    Filename,

    CapacityGB,

    @{N = 'VMDK Uuid'; E = {$_.ExtensionData.Backing.Uuid}},

    @{N = 'SCSIid'; E = {

       $hd = $_

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

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

       }

    },

    @{N = 'Controller#'; E = {(Get-ScsiController -HardDisk $_).UnitNumber}} |

       Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture



  • 20.  RE: Get Virtual Disk SCSI-IDs

    Posted Aug 21, 2019 10:11 PM

    After exporting the information to .csv file and when the csv file is opened with Excel the SCSI id value get change from 0:0 to 00:00 , 0:1 to 00:01 .. and so on. Can we restrict or format the column values while exporting? 

                                                                                                                
    VMNameFilenameSCSIid
    CH_Win2016Hard disk 1[iSCSI-2] CH_Win2016/CH_Win2016.vmdk00:00
    CH_Win2016Hard disk 2[iSCSI-2] CH_Win2016/CH_Win2016_1.vmdk00:01
    CH_Win2016Hard disk 3[iSCSI-2] CH_Win2016/CH_Win2016_2.vmdk00:02


  • 21.  RE: Get Virtual Disk SCSI-IDs

    Posted Aug 21, 2019 10:22 PM

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

    You could replace the ':' by something else.



  • 22.  RE: Get Virtual Disk SCSI-IDs

    Posted Nov 26, 2019 05:11 AM

    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



  • 23.  RE: Get Virtual Disk SCSI-IDs

    Posted Nov 26, 2019 05:43 AM

    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



  • 24.  RE: Get Virtual Disk SCSI-IDs

    Posted Jan 18, 2019 10:35 AM

    I have checked the output and I'm not quite sure how to interpret the output for the SCSI controller. The Output is mostly 3 or 4 but not SCSI Controller 0 or SCSI Controller 1 as expected. Maybe the controller UnitNumber are different values. Can the output of SCSI Controller 0 like seen in the WebClient also be exported?



  • 25.  RE: Get Virtual Disk SCSI-IDs

    Posted Jan 18, 2019 10:50 AM

    Isn't that 1st number (the BusNumber) in the SCSIid?



  • 26.  RE: Get Virtual Disk SCSI-IDs

    Posted Sep 10, 2019 09:38 AM

    $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