PowerCLI

 View Only
Expand all | Collapse all

PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

winsolo

winsoloJul 06, 2020 06:08 PM

  • 1.  PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 02, 2016 05:22 AM

    Hi All,

    Can anyone here please assist me with the powershell script if possible to list the VM information like the following format or in CSV format is OK:

    SCSI (0:0) VM Hard Disk 1 [R5D23] PRODFSCLUS01-VM/PRODFSCLUS01-VM.vmdk - Windows C: drive - 60 GB

    SCSI (1:1) VM Hard Disk 2 [NAS-D76] PRODFSCLUS01-VM/PRODFSCLUS01-VM.vmdk - Windows Q: drive - 1 GB

    SCSI (1:2) VM Hard Disk 3 [NAS-D23] PRODFSCLUS01-VM/PRODFSCLUS01-VM.vmdk - Windows G: drive - 1.77 TB

    SCSI (1:3) VM Hard Disk 4 [R5D52] PRODFSCLUS01-VM/PRODFSCLUS01-VM.vmdk - Windows H: drive - 1.77 GB

    SCSI (1:4) VM Hard Disk 5 [NAS-D19] PRODFSCLUS01-VM/PRODFSCLUS01-VM.vmdk - Windows T: drive - 60 GB

    Thanks in advance.



  • 2.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 03, 2016 12:34 AM

    The below pieces would help to grab the info

    $VM = Get-VM

    $VM.HardDisks | Select Name,Filename

    $vmg = $VM | Get-VMGuest

    $vmg.Disks | select Path,CapacityGB,FreeGB



  • 3.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 03, 2016 06:15 AM

    If you don't have more than one guest OS partition on a VMDK, you can use something like this

    $compName = 'MyVM'

    $volTab = @{}

    foreach($disk in (Get-CimInstance -ComputerName $compName -ClassName Win32_DiskDrive)){

        foreach($partition in (Get-CimAssociatedInstance -InputObject $disk -ResultClassName Win32_DiskPartition)){

            Get-CimAssociatedInstance -InputObject $partition -ResultClassName Win32_LogicalDisk | %{

                $volTab.Add("$($disk.SCSIBus):$($disk.SCSITargetId)",($_.DeviceID,$_.VolumeName -join '|'))

            }

        }

    }

    $vm = Get-VM -Name $compName

    foreach($ctrl in Get-ScsiController -VM $vm){

        foreach($disk in (Get-HardDisk -VM $vm | where{$_.ExtensionData.ControllerKey -eq $ctrl.Key})){

            $obj = [ordered]@{

                VM = $vm.name

                HD = $disk.Name

                VMDK = $disk.Filename

                Device = "$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"

                Drive = ""

                Label = ""

            }

            if($volTab.ContainsKey("$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)")){

                $obj.Drive = $volTab["$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"].Split('|')[0]

                $obj.Label = $volTab["$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"].Split('|')[1]

            }

            New-Object -TypeName PSObject -Property $obj

        }

    }



  • 4.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 03, 2016 06:31 AM

    yes that's the one almost. .:smileygrin:

    Somehow the Drive letter and label is still not populated ?



  • 5.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 03, 2016 06:33 AM

    I've tried using:

    #Example snippet to tie a Windows Volume to a VMware

    #Define computername

        $computer = "PRODFS03-VM"

    #Change this as needed.  Our standard display name is the hostname followed by a space...

        $VMView = Get-View -ViewType VirtualMachine -Filter @{'Name' = "$computer "}

    #Thanks go to Richard Siddaway for the basic queries to tie diskdrive>partition>logicaldisk.

    #http://itknowledgeexchange.techtarget.com/powershell/mapping-physical-drives-to-logical-drives-part-3/

        $ServerDiskToVolume = @(

            Get-WmiObject -Class Win32_DiskDrive -ComputerName $computer | foreach {

           

                $Dsk = $_

                $query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($_.DeviceID)'} WHERE ResultClass=Win32_DiskPartition"

           

                Get-WmiObject -Query $query -ComputerName $computer | foreach {

               

                    $query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$($_.DeviceID)'} WHERE ResultClass=Win32_LogicalDisk"

               

                    Get-WmiObject -Query $query -ComputerName $computer | Select DeviceID,

                        VolumeName,

                        @{ label = "SCSITarget"; expression = {$dsk.SCSITargetId} },

                        @{ label = "SCSIBus"; expression = {$dsk.SCSIBus} }

                }

            }

        )

    # Now loop thru all the SCSI controllers on the VM and find those that match the Controller and Target

        $VMDisks = 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}))

            {

                #Build a custom object to hold this.  We use PS3 language...

                [pscustomobject]@{

                    VM = $VM.Name

                    HostName = $VMView.Guest.HostName

                    PowerState = $VM.PowerState

                    DiskFile = $VirtualDiskDevice.Backing.FileName

                    DiskName = $VirtualDiskDevice.DeviceInfo.Label

                    DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB

                    SCSIController = $VirtualSCSIController.BusNumber

                    SCSITarget = $VirtualDiskDevice.UnitNumber

                    DeviceID = $null

                }

           

                #Match up this VM to a logical disk

                    $MatchingDisk = @( $ServerDiskToVolume | Where {$_.SCSITarget -like $VMSummary.SCSITarget -and $_.SCSIBus -like $VMSummary.SCSIController} )

               

                #Shouldn't happen, but just in case..

                    if($MatchingDisk.count -gt 1)

                    {

                        Write-Error "too many matches: $($MatchingDisk | select -property deviceid, partitions, SCSI* | out-string)"

                        $VMSummary.DeviceID = "Error: Too Many"

                    }

                    elseif($MatchingDisk.count -eq 1)

                    {

                        $VMSummary.DeviceID = $MatchingDisk.DeviceID

                    }

                    else

                    {

                        Write-Error "no match found"

                        $VMSummary.DeviceID = "Error: None found"

                    }

                $VMSummary

            }

        }

    but it is not returning any result ?



  • 6.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 03, 2016 06:42 AM

    That is in fact the script I replied to earlier, but that thread seems to have disappeared overnight :smileyconfused:

    The script you mention is the pre-PSv3 way of doing it, in PSv3 the Get-CimAssociatedInstance  cmdlet was introdcued, which avoids these awful ASSOCIATORS queries.

    If the drive letter and label are not there, that would mean that the WMI queries don't find the info.

    What does this show for that specific VM ?

    $compName = 'MyVM'

    $volTab = @{}

    foreach($disk in (Get-CimInstance -ComputerName $compName -ClassName Win32_DiskDrive)){

        foreach($partition in (Get-CimAssociatedInstance -InputObject $disk -ResultClassName Win32_DiskPartition)){

            Get-CimAssociatedInstance -InputObject $partition -ResultClassName Win32_LogicalDisk | %{

                $volTab.Add("$($disk.SCSIBus):$($disk.SCSITargetId)",($_.DeviceID,$_.VolumeName -join '|'))

            }

        }

    }

    $volTab.GetEnumerator()



  • 7.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 03, 2016 10:36 PM

    LucD‌ it returns as follows:

    Exception calling "Add" with "2" argument(s): "Item has already been added. Key in dictionary: '0:0'  Key being added: '0:0'"

    At C:\Users\Admin\AppData\Local\Temp\b19a36b6-f1ed-4bff-bc63-f411d95c083d.ps1:8 char:45

    + ...            $volTab.Add("$($disk.SCSIBus):$($disk.SCSITargetId)",($_.D ...

    +                                                ~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : ArgumentException

    Name                           Value                                                                                                                                                                                                  

    ----                           -----                                                                                                                                                                                                  

    0:0                            C:|C-PRODFS03-VM    



  • 8.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 04, 2016 05:56 AM

    That seems to indicate that you have duplicate bus:scsiid entries on a VM, which shouldn't be possible.

    What does this produce for that VM ?

    $compName = 'MyVM'

    foreach($disk in (Get-CimInstance -ComputerName $compName -ClassName Win32_DiskDrive)){

        foreach($partition in (Get-CimAssociatedInstance -InputObject $disk -ResultClassName Win32_DiskPartition)){

            Get-CimAssociatedInstance -InputObject $partition -ResultClassName Win32_LogicalDisk | %{

                Write-Output "$($disk.SCSIBus):$($disk.SCSITargetId) $($_.DeviceID) $($_.VolumeName)"

            }

        }

    }



  • 9.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 04, 2016 06:28 AM

    LucD‌ the result is:

    0:0 C: C-PRODFS03-VM

    0:0 E: E-PRODFS03-VM

    from the vSphere console I can see that the E: drive is on SCSI 1:0 not 0:0

    same thing with the other VM:

    0:0 C: C-PRODPXE01-VM

    0:0 D: D-OS IMAGES

    All returns 0:0



  • 10.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 04, 2016 06:58 AM

    Can you check this variation ?

    $compName = 'MyVM'

    foreach($disk in (Get-CimInstance -ComputerName $compName -ClassName Win32_DiskDrive)){

        foreach($partition in (Get-CimAssociatedInstance -InputObject $disk -ResultClassName Win32_DiskPartition)){

            Get-CimAssociatedInstance -InputObject $partition -ResultClassName Win32_LogicalDisk | %{

                Write-Output "$($disk.SCSIPort-2):$($disk.SCSITargetId) $($_.DeviceID) $($_.VolumeName)"

            }

        }

    }



  • 11.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 06, 2016 09:17 PM

    LucD‌ Yes it is getting better Luc,

    The result now shows the SCSI ID better:

    0:0 C: C-PRODFS03-VM

    1:0 D: D-PRODFS03-VM

    Previously the D: drive is the same 0:0



  • 12.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 11, 2016 06:10 AM

    LucD‌ this is the script that I've found somehwere in this forum:

    $report = @()

    foreach($vm in Get-VM -Name "PRODFS03-VM","PRODSQLDB02-VM" ){

        Get-HardDisk -VM $vm | ForEach-Object {

            $HardDisk = $_

            $row = "" | Select Hostname, VM, GuestName, Datastore, VMXpath, HardDisk, DiskType, CapacityGB, DiskUsage

                        $row.Hostname = $vm.Host.Name

                        $row.VM = $VM.Name

                        $row.GuestName = $vm.Guest.HostName

                        $row.Datastore = $HardDisk.Filename.Split("]")[0].TrimStart("[")

                        $row.VMXpath = $HardDisk.FileName

                        $row.HardDisk = $HardDisk.Name

                        $row.CapacityGB = ("{0:f1}" -f ($HardDisk.CapacityKB/1MB))

      $row.DiskType = $HardDisk.get_DiskType()

      $row.DiskUsage = $vm.get_UsedSpaceGB()

                        $report += $row

       }

     

    }

    $report | ft -AutoSize

    This is the result from the script above:

    What missing is the drive letter column that I'm interested to know if it is possible.


    Thanks so far for the assistance.



  • 13.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 11, 2016 07:25 AM

    Did you already combine that with the last script I gave in this thread ?



  • 14.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 11, 2016 07:40 AM

    LucD‌ ah I'm not sure how to combine it with your script hence I was just asking if it is possible :smileygrin:



  • 15.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Dec 15, 2016 07:40 AM

    I'm also having problems to find or write a script that reports the VMDK, SCSI ID, Windows drive letters. The best I could find is the following;

    VMware: matching guest drives to .vmdk files? - Ars Technica OpenForum

    It works nicely as long as the VM has only a one SCSI controller. Any idea to modify the script to work with multipe SCSI controller?

    VM       HostName              DiskFile                                      DiskName       DiskSize SCSIController SCSITarget DeviceID

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

    xxxx2019 xxxx2019      [xx_Tiering_LUN038] xxxx2019/xxxx2019.vmdk    Hard disk 1 42949672960              0          0 {D:, C:}

    xxxx2019 xxxx2019      [xx_Tiering_LUN038] xxxx2019/xxxx2019_1.vmdk Hard disk 2 21474836480              1          0       

    xxxx2019 xxxx2019      [xx_Tiering_LUN038] xxxx2019/xxxx2019_2.vmdk Hard disk 3 75161927680              1          1       



  • 16.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Dec 15, 2016 04:19 PM

    I've now a solution that returns data for VM's with two SCSI Controller. Funny thing is that for at least one VM I still get wrong results. This VM has 4 controllers, but only 3 have attached disks. This seems to confuse the scrip.Not sure which other VM's might have false results.

    VM:

    HD1     SCSI  0 0

    HD2     SCSI 1 0

    HD3     SCSI 3 0  (note: not 2 0)

    $ServerDiskToVolume: SCSI Bus is wrong for D drive. It should be 0 3.

    DeviceID                                            VolumeName                                                                                  SCSITarget                                            SCSIBus

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

    D:                                                  xxxx_D                                                                                           0                                                  2

    E:                                                  xxxx_E                                                                                           0                                                  1

    C:                                                  xxxx_C                                                                                           0                                                  0

    Thus in the script result D:is missing as Device ID.

    VM       HostName           DiskFile                                               DiskName         DiskSize SCSIController SCSITarget DeviceID

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

    xxxx xxxx [xxxx_LUN048] xxxx/xxxx.vmdk   Hard disk 1   53687091200              0          0 C:     

    xxxx xxxx [xxxx_LUN048] xxxx/xxxx_1.vmdk Hard disk 2 1503238553600              1          0 E:     

    xxxx xxxx [xxxx_LUN048] xxxx/xxxx_3.vmdk Hard disk 3 1099511627776              3          0        

    #Example snippet to tie a Windows Volume to a VMware

    clear

    $cred = Get-Credential -Credential "xxxx"

    #Define computername

    $computers = "xxxx"

    foreach ($computer in $computers) {

    Write $computer

    #Change this as needed. Our standard display name is the hostname followed by a space...

    $VMView = Get-VM -Name $computer | Get-View

    $session = New-CimSession –ComputerName $computer -Credential $cred

    $ServerDiskToVolume = @(

    foreach($disk in (Get-CimInstance -CimSession $session -ClassName Win32_DiskDrive)){

        #Write-Output "Disk: " $disk

      foreach($partition in (Get-CimAssociatedInstance -CimSession $session -InputObject $disk -ResultClassName Win32_DiskPartition)){

            #Write-Output "Partition: " $partition

      Get-CimAssociatedInstance -CimSession $session -InputObject $partition -ResultClassName Win32_LogicalDisk | select DeviceID, VolumeName,

                #Write-Output "$($disk.SCSIPort-2):$($disk.SCSITargetId) $($_.DeviceID) $($_.VolumeName)"

      @{ label = "SCSITarget"; expression = {$disk.SCSITargetId} },

      @{ label = "SCSIBus"; expression = {$disk.SCSIPort-2} }

            }

        }

    Remove-CimSession -Name  *

    )

    <# Commented out for later use.

    $ServerDiskToVolume = @(

      Get-WmiObject -Credential $cred -Class Win32_DiskDrive -ComputerName $computer | foreach {

      $Dsk = $_

      $query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($_.DeviceID)'} WHERE ResultClass=Win32_DiskPartition"

      Get-WmiObject -Credential $cred -Query $query -ComputerName $computer | foreach {

      $query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$($_.DeviceID)'} WHERE ResultClass=Win32_LogicalDisk"

      Get-WmiObject -Credential $cred -Query $query -ComputerName $computer | Select DeviceID,VolumeName,

      @{ label = "SCSITarget"; expression = {$dsk.SCSITargetId} },

      @{ label = "SCSIBus"; expression = {$dsk.SCSIPort-2} }

      }

      }

    )

    #>

    Write-Output $ServerDiskToVolume

    # Now loop thru all the SCSI controllers on the VM and find those that match the Controller and Target

    $VMDisks = 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})) {

      #Match up this VM to a logical disk

      $MatchingDisk = @( $ServerDiskToVolume | Where {$_.SCSITarget -eq $VirtualDiskDevice.UnitNumber -and $_.SCSIBus -eq $VirtualSCSIController.BusNumber} )

      #Build a custom object to hold this. We use PS3 language...

      [pscustomobject]@{

      VM = $VMView.Name

      HostName = $VMView.Guest.HostName

      DiskFile = $VirtualDiskDevice.Backing.FileName

      DiskName = $VirtualDiskDevice.DeviceInfo.Label

      DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB

      SCSIController = $VirtualSCSIController.BusNumber

      SCSITarget = $VirtualDiskDevice.UnitNumber

      DeviceID = $MatchingDisk.DeviceID

      }

      }

    }

    $VMDisks | ft -AutoSize #| out-file -append c:\Users\rfg\vm_disk.txt

    }



  • 17.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Dec 15, 2016 10:02 PM

    Look at something I posed a couple days ago:  How to trace a VM disk to a guest disk.

    That should help you associate VMware disk to OS disk - should work any number of scsi adapters.  The methodology should work for any OS although the script I provided is for Windows.

    That script does not address your requirement for needing to correlate drive letters to a disk.  But I do have some stuff that will do that in Windows as long as psremoting is enabled on your guest (drive letters don't need psremoting, but mountpoints do).  If you need help with that then post a new question and I'll try to assist this evening.



  • 18.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Dec 23, 2023 03:14 AM

    #This script based on his, also associates de drive letter:

    $computer = "VMNAME"

    $VMView = Get-View -ViewType VirtualMachine -Filter @{'Name' = "^$($computer)$"}

    # Obtén información sobre discos y particiones
    $ServerDiskToVolume = @(

    Get-WmiObject -Class Win32_DiskDrive -ComputerName $computer | foreach {

    $Dsk = $_
    $query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($_.DeviceID)'} WHERE ResultClass=Win32_DiskPartition"

    Get-WmiObject -Query $query -ComputerName $computer | foreach {

    $query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$($_.DeviceID)'} WHERE ResultClass=Win32_LogicalDisk"

    Get-WmiObject -Query $query -ComputerName $computer | Select DeviceID,
    VolumeName,
    @{ label = "SCSITarget"; expression = {$dsk.SCSITargetId} },
    @{ label = "SCSIBus"; expression = {$dsk.SCSIBus} }
    }
    }
    )

    # Now loop through all the SCSI controllers on the VM and find those that match the Controller and Target
    $VMDisks = 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})) {

    # Build a custom object to hold this.
    $VMSummary = [pscustomobject]@{
    VM = $VM.Name
    HostName = $VMView.Guest.HostName
    PowerState = $VM.PowerState
    DiskFile = $VirtualDiskDevice.Backing.FileName
    DiskName = $VirtualDiskDevice.DeviceInfo.Label
    DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB
    SCSIController = $VirtualSCSIController.BusNumber
    SCSITarget = $VirtualDiskDevice.UnitNumber
    DeviceID = $null
    }

    # Match up this VM to a logical disk
    $MatchingDisk = $ServerDiskToVolume | Where { $_.SCSITarget -eq $VMSummary.SCSITarget -and $_.SCSIBus -eq $VMSummary.SCSIController }

    if ($MatchingDisk) {
    $VMSummary.DeviceID = $MatchingDisk.DeviceID
    } else {
    $VMSummary.DeviceID = "Offline"
    }

    $VMSummary
    }
    }

    # Output the combined information as an autosized table
    $VMDisks | Format-Table -AutoSize



  • 19.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Jan 19, 2020 04:39 PM

    Hi LuCD,

    In my environment CIM instance & WMI is not working as they are not enabled..

    I tried the invoke-vmscript and it gives me the output without CIM Instance & WMI.

    How can we modify the script and use 'Invoke-VMScript -VM $VM -ScriptType Powershell "Get-WmiObject -Class Win32_DiskDrive"'. 

    Thanks

    Bikash



  • 20.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Jan 19, 2020 09:38 PM

    Do you mean remote WMI is disabled?

    Otherwise it will not work via Invoke-VMScript either.

    Btw, it should probably (and possible also provide guest credentials)

    Invoke-VMScript -VM $VM -ScriptType Powershell -ScriptText "Get-WmiObject -Class Win32_DiskDrive"


  • 21.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Jan 20, 2020 04:35 AM

    HI LucD,

    Below is the output i am getting. Only Invoke-VMScript is working. How can we modify the script and use Invoke-VMScript to have the same output.

    PS C:\Users\Documents> Get-CimInstance -ComputerName $VM -ClassName Win32_DiskDrive
    Get-CimInstance : The connection to the specified remote host was refused. Verify that the WS-Management service is running on the remote host and configured to listen
    for requests on the correct port and HTTP URL.
    At line:1 char:1
    + Get-CimInstance -ComputerName $VM -ClassName Win32_DiskDrive
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ResourceBusy: (root\cimv2:Win32_DiskDrive:String) [Get-CimInstance], CimException
        + FullyQualifiedErrorId : HRESULT 0x80338112,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
        + PSComputerName        : XXXXX

    PS C:\Users\Documents> Get-WmiObject -Class Win32_DiskDrive -ComputerName $VM
    Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    At line:1 char:1
    + Get-WmiObject -Class Win32_DiskDrive -ComputerName $VM
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
        + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    PS C:\Users\Documents> Invoke-Command -ComputerName $VM -ScriptBlock {Get-WmiObject -Class Win32_DiskDrive}
    [XXXXX] Connecting to remote server XXXXX failed with the following error message : The connection to the specified remote host was refused. Verify that the
    WS-Management service is running on the remote host and configured to listen for requests on the correct port and HTTP URL. For more information, see the
    about_Remote_Troubleshooting Help topic.
        + CategoryInfo          : OpenError: (XXXXX:String) [], PSRemotingTransportException
        + FullyQualifiedErrorId : CannotConnectWinRMService,PSSessionStateBroken


    PS C:\Users\Documents> Invoke-VMScript -VM $VM -ScriptType Powershell "Get-WmiObject -Class Win32_DiskDrive"

    ScriptOutput
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    |
    |
    |  Partitions : 1
    |  DeviceID   : \\.\PHYSICALDRIVE5
    |  Model      : VMware Virtual disk SCSI Disk Device
    |  Size       : 536864025600
    |  Caption    : VMware Virtual disk SCSI Disk Device
    |
    |  Partitions : 1
    |  DeviceID   : \\.\PHYSICALDRIVE7
    |  Model      : VMware Virtual disk SCSI Disk Device
    |  Size       : 644245056000
    |  Caption    : VMware Virtual disk SCSI Disk Device
    |
    |  Partitions : 1
    |  DeviceID   : \\.\PHYSICALDRIVE1
    |  Model      : VMware Virtual disk SCSI Disk Device
    |  Size       : 64420392960
    |  Caption    : VMware Virtual disk SCSI Disk Device
    |
    |  Partitions : 1
    |  DeviceID   : \\.\PHYSICALDRIVE10
    |  Model      : VMware Virtual disk SCSI Disk Device
    |  Size       : 1649267343360
    |  Caption    : VMware Virtual disk SCSI Disk Device
    |
    |  Partitions : 1
    |  DeviceID   : \\.\PHYSICALDRIVE4
    |  Model      : VMware Virtual disk SCSI Disk Device
    |  Size       : 53686402560
    |  Caption    : VMware Virtual disk SCSI Disk Device

    Thanks

    Bikash



  • 22.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Jan 20, 2020 09:45 AM

    What you are seeing is the default output from that WMI object.
    If you want to see different properties, you will have to use the Select-Object cmdlet



  • 23.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Jan 20, 2020 05:12 PM

    Hi LucD,

    Since you saw the output result n it's clear that only invoke-vmscript gives me a valid output.if I run Get-Ciminstance for a remote computer it doesn't work n I have to use invoke-vmscript to get Get-Ciminstance output.

    So how do I modify this script as and use invoke-vmscript.

    $compName = 'MyVM'

    $volTab = @{}

    foreach($disk in (Get-CimInstance -ComputerName $compName -ClassName Win32_DiskDrive)){

        foreach($partition in (Get-CimAssociatedInstance -InputObject $disk -ResultClassName Win32_DiskPartition)){

            Get-CimAssociatedInstance -InputObject $partition -ResultClassName Win32_LogicalDisk | %{

                $volTab.Add("$($disk.SCSIBus):$($disk.SCSITargetId)",($_.DeviceID,$_.VolumeName -join '|'))

            }

        }

    }

    $vm = Get-VM -Name $compName

    foreach($ctrl in Get-ScsiController -VM $vm){

        foreach($disk in (Get-HardDisk -VM $vm | where{$_.ExtensionData.ControllerKey -eq $ctrl.Key})){

            $obj = [ordered]@{

                VM = $vm.name

                HD = $disk.Name

                VMDK = $disk.Filename

                Device = "$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"

                Drive = ""

                Label = ""

            }

            if($volTab.ContainsKey("$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)")){

                $obj.Drive = $volTab["$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"].Split('|')[0]

                $obj.Label = $volTab["$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"].Split('|')[1]

            }

            New-Object -TypeName PSObject -Property $obj

        }

    }



  • 24.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Jan 20, 2020 05:34 PM

    Instead of transferring the complete WMI object, you can do the extraction of the required properties on the target station.

    Use this as an example.
    It transfers the required data in CSV format, which on the calling side is then converted back to an object.

    Which you can use in your script

    $vmName = 'MyVM'

    $user = 'domain\user'

    $pswd = 'VMware1!'


    $secPswd = ConvertTo-SecureString -String $pswd -AsPlainText -Force

    $cred = New-Object System.Management.Automation.PSCredential ($user, $secPswd)


    $code = @'

    $info = foreach($disk in (Get-CimInstance -ClassName Win32_DiskDrive)){

        foreach($partition in (Get-CimAssociatedInstance -InputObject $disk -ResultClassName Win32_DiskPartition)){

            Get-CimAssociatedInstance -InputObject $partition -ResultClassName Win32_LogicalDisk | select DeviceID, VolumeName,

                @{ label = "SCSITarget"; expression = {$disk.SCSITargetId} },

                @{ label = "SCSIBus"; expression = {$disk.SCSIPort-2} }

        }

    }

    $info | ConvertTo-Csv -NoTypeInformation -UseCulture

    '@


    $vm = Get-VM -Name $vmName


    $sInvoke = @{

        VM = $VM

        ScriptType = 'Powershell'

        ScriptText = $code

        GuestCredential = $cred

    }

    Invoke-VMScript @sInvoke |

    Select -ExpandProperty ScriptOutput |

    ConvertFrom-Csv -UseCulture



  • 25.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Mar 04, 2022 06:09 PM

    How can I make this disk association to Linux server partitions (Red Hat Enterprise)



  • 26.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 09, 2020 12:32 PM

    I too wanted to determine the association between vmware scsi devices and their windows partitions and drive letters. 

    Starting with the information gleaned from  Map VMware virtual disks and Windows drive volumes with a PowerShell script – 4sysops​ I knew I could not reliably match Windows and VMWare SCSI bus numbers.  I was on my own.  I started by generating detailed information from both VMWare and Windows environments.  I then summarized each environment's SCSI controller information based on number of SCSI target IDs and total disk space used on all drives.  I discovered that once I sorted these summaries, I could see a one-to-one mapping between the VMWare and Windows SCSI controllers.  Once I had a valid mapping, I could then update my VMWare report with the missing Windows information (serial number, disk size, number of partitions, drive letters). 

    If WMI is accessible for the VMs in question, the script will map VMWare to Windows partitions.  If WMI is not available, it will at least show you the VMWare side of the equation.



  • 27.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 09, 2020 01:25 PM

    You might want to have a look at the Get-VMGuestDisk cmdlet, new in PowerCLI 12.0.



  • 28.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 09, 2020 01:41 PM

    Get-VMGuestDisk requires vSphere version 7.0 and later.



  • 29.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 09, 2020 01:49 PM

    Seems like Get-VMGuestDisk requires vsphere 7 and later plus vmtool 11.x



  • 30.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 09, 2020 02:51 PM

    That is correct, those are some of the requirements.



  • 31.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 30, 2020 11:42 AM

    Hi LucD,

    Still stuggling to get the Drive letter and disk number on single report.

    was tried for class-  Win32_DiskDrive command to get the report got failed "WinRM error"

    there is any possibility t get the report using vm.Guest.Disks command along with harddisk number

    $DiskInfo= @()

    foreach ($VMview in Get-VM VMname | 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

    $VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName

    $VirtualDisk.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB

    $DiskInfo +=$VirtualDisk

    }}}

    $DiskInfo | sort VMname, Diskname | Export-Csv -Path C:\temp\server.csv

    ForEach-Object {$vm.Guest.Disks | ForEach-Object {

        $VirtualDisk1 = "" | Select-Object -Property Path,capacity

        $VirtualDisk1.Path = $_.Path

        $VirtualDisk1.Capacity = $_.Capacity

    $DiskInfo +=$VirtualDisk1

      }

    }



  • 32.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?
    Best Answer

    Posted Apr 30, 2020 01:04 PM

    Not sure if you have read my previous comments, but there is no fool-proof method to map Guest OS partitions/drives to VMDK files.

    With Get-VMGuestDisk this has changed, but there are prerequisites.



  • 33.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 30, 2020 06:28 PM

    Thank you for the information ,

    finally as per your suggesting have made below script , please help to add to scsicanonicalname and export to csv format.

    $volTab = @{}

    foreach($disk in (Get-CimInstance  -ClassName Win32_DiskDrive)){

        foreach($partition in (Get-CimAssociatedInstance -InputObject $disk -ResultClassName Win32_DiskPartition)){

            Get-CimAssociatedInstance -InputObject $partition -ResultClassName Win32_LogicalDisk | %{

                $volTab.Add("$($disk.SCSIBus):$($disk.SCSITargetId)",($_.DeviceID,$_.VolumeName -join '|'))

            }

        }

    }

    foreach($ctrl in Get-ScsiController -VM $vm){

        foreach($disk in (Get-HardDisk -VM $vm | where{$_.ExtensionData.ControllerKey -eq $ctrl.Key})){

            $obj = [ordered]@{

                VM = $vm.name

                HD = $disk.Name

                VMDK = $disk.Filename

                Device = "$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"

                Drive = ""

                Label = ""

            }

            if($volTab.ContainsKey("$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)")){

                $obj.Drive = $volTab["$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"].Split('|')[0]

                $obj.Label = $volTab["$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"].Split('|')[1]

            }

            New-Object -TypeName PSObject -Property $obj

        }

    }



  • 34.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted May 01, 2020 02:03 AM

    So not even Vmware Tools v11 and ESXi v7 can get consistent result from PowerCLI?



  • 35.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted May 01, 2020 05:52 AM

    There are also some prerequisites on the Guest OS, although it seems to work on several Linux based Guest OS.

    Another limiting factor is apparently the filesystem type used, I haven't found a definitive list of which types are supported or not.

    Are you seeing issues?
    On which Guest OS and which filesystem type?



  • 36.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted May 01, 2020 06:19 AM

    Hi LucD,

    Below scripts work for me. Can you help me modify the below script to get linux machine details.

    param ([ string ]$VMName )

    #Define computername

    $computer = $VMName

    $VMView = Get-VM -Name $computer | Get-View

    $ServerDiskToVolume = @(

    Get-WmiObject -Class Win32_DiskDrive | foreach {

    $Dsk = $_

    $query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($_.DeviceID)'} WHERE ResultClass=Win32_DiskPartition"

    Get-WmiObject -Query $query | foreach {

    $query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$($_.DeviceID)'} WHERE ResultClass=Win32_LogicalDisk"

    Get-WmiObject -Query $query | Select DeviceID,

    VolumeName,

    @{ label = "SCSITarget"; expression = {$dsk.SCSITargetId} },

    @{ label = "SCSIBus"; expression = {$dsk.SCSIBus} }

    }

    }

    )

    $VMDisks = 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}))

    {

    $MatchingDisk = @( $ServerDiskToVolume | Where {$_.SCSITarget -eq $VirtualDiskDevice.UnitNumber -and $_.SCSIBus -eq $VirtualSCSIController.BusNumber} )

    [pscustomobject]@{

    VM = $VMView.Name

    #HostName = $VMView.Guest.HostName

    DiskFile = $VirtualDiskDevice.Backing.FileName

    DiskName = $VirtualDiskDevice.DeviceInfo.Label

    DiskSizeGB = $VirtualDiskDevice.CapacityInKB / 1024KB

    #SCSIController = $VirtualSCSIController.BusNumber

    #SCSITarget = $VirtualDiskDevice.UnitNumber

    SCSIid = "$($VirtualSCSIController.BusNumber):$($VirtualDiskDevice.UnitNumber)"

    DeviceID = $MatchingDisk.DeviceID

    }

    }

    }

    $VMDisks | ft -AutoSize

    Thanks

    Bikash



  • 37.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted May 01, 2020 06:37 AM

    I don't know how many times I have to repeat this but there is no foolproof method, before Get-VMGuestDisk, of mapping Guest OS partitions/drives to VMDK.

    Your script "works" for a Windows Guest OS and in your specific situation.

    The script is partially based on some Windows methods and properties that do not exist in a Linux Guest OS.

    There is no straight-forward way to replicate that script for a Linux Guest OS.



  • 38.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted May 03, 2020 10:53 AM

    Hi Lucd,

    pls assist export the result to csv file, this script is working , only required only export outupt file and due to remote execution policy "Win32_DiskDrive.DeviceID " is not working on our premises,

    $volTab = @{}

    foreach($disk in (Get-CimInstance  -ClassName Win32_DiskDrive)){

        foreach($partition in (Get-CimAssociatedInstance -InputObject $disk -ResultClassName Win32_DiskPartition)){

            Get-CimAssociatedInstance -InputObject $partition -ResultClassName Win32_LogicalDisk | %{

                $volTab.Add("$($disk.SCSIBus):$($disk.SCSITargetId)",($_.DeviceID,$_.VolumeName -join '|'))

            }

        }

    }

    foreach($ctrl in Get-ScsiController -VM $vm){

        foreach($disk in (Get-HardDisk -VM $vm | where{$_.ExtensionData.ControllerKey -eq $ctrl.Key})){

            $obj = [ordered]@{

                VM = $vm.name

                HD = $disk.Name

                VMDK = $disk.Filename

                Device = "$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"

                Drive = ""

                Label = ""

            }

            if($volTab.ContainsKey("$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)")){

                $obj.Drive = $volTab["$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"].Split('|')[0]

                $obj.Label = $volTab["$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"].Split('|')[1]

            }

            New-Object -TypeName PSObject -Property $obj

        }

    }



  • 39.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted May 03, 2020 11:05 AM

    The foreach statement doesn't place anything in the pipeline.

    It is easier to use the Foreach-Object cmdlet in combination with the Pipeline parameter.

    Like this

    Get-ScsiController -VM $vm -PipelineVariable ctrl |

    ForEach-Object -Process {

        Get-HardDisk -VM $vm -PipelineVariable disk | where{$_.ExtensionData.ControllerKey -eq $ctrl.Key} |

        ForEach-Object -Process {

            $obj = [ordered]@{

                VM = $vm.name

                HD = $disk.Name

                VMDK = $disk.Filename

                Device = "$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"

                Drive = ""

                Label = ""

            }

            if($volTab.ContainsKey("$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)")){

                $obj.Drive = $volTab["$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"].Split('|')[0]

                $obj.Label = $volTab["$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"].Split('|')[1]

            }

            New-Object -TypeName PSObject -Property $obj

        }

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



  • 40.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Jul 06, 2020 06:08 PM

    Thanks for the script. It worked.



  • 41.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Jul 07, 2020 05:37 AM


  • 42.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Feb 11, 2021 06:31 PM

    I know this is an old thread, but I took some snippets from the code included and built something that works with VMware 6.7. The next step is including the process to expand the VMDK and then expand in the OS. I will post that script in a new thread once it is working. Note: I wanted Size, not Lable, but that is an easy change.

    $vmName = 'MyVM'
    $user = 'domain\user'
    $pswd = 'password'

    $secPswd = ConvertTo-SecureString -String $pswd -AsPlainText -Force
    $cred = New-Object System.Management.Automation.PSCredential ($user, $secPswd)


    $code = @'
    $compName = '.'
    $test = $null
    foreach($disk in (Get-CimInstance -ComputerName $compName -ClassName Win32_DiskDrive)){
    foreach($partition in (Get-CimAssociatedInstance -InputObject $disk -ResultClassName Win32_DiskPartition)){
    Get-CimAssociatedInstance -InputObject $partition -ResultClassName Win32_LogicalDisk | %{
    $test += "$($disk.SCSIBus):$($disk.SCSITargetId)","=",($_.DeviceID),"|",[math]::round($_.size/1024/1024/1024) -join ""
    $test += "`r`n"
    }
    }
    }
    $test
    '@


    $vm = Get-VM -Name $vmName

    $sInvoke = @{
    VM = $VM
    ScriptType = 'Powershell'
    ScriptText = $code
    GuestCredential = $cred
    }

    $volTab = @{}
    $volTab = Invoke-VMScript @sInvoke | Select -ExpandProperty ScriptOutput | ConvertFrom-StringData

    $vm = Get-VM -Name $vmName

    foreach($ctrl in Get-ScsiController -VM $vm){
    foreach($disk in (Get-HardDisk -VM $vm | where{$_.ExtensionData.ControllerKey -eq $ctrl.Key})){
    $obj = [ordered]@{
    VM = $vm.name
    HD = $disk.Name
    VMDK = $disk.Filename
    Device = "$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"
    Drive = ""
    Size = ""
    }

    if($volTab.ContainsKey("$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)")){
    $obj.Drive = $volTab["$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"].Split('|')[0]
    $obj.Size = $volTab["$($ctrl.ExtensionData.BusNumber):$($disk.ExtensionData.UnitNumber)"].Split('|')[1]
    }
    New-Object -TypeName PSObject -Property $obj
    }
    }

     



  • 43.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Feb 11, 2021 06:46 PM

    If your VMware Tools are on the correct version, you can use the Get-VMGuestDisk cmdlet.



  • 44.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Feb 11, 2021 06:53 PM

    I have PowerCLI 12.0.1 installed, but we are still on vSphere 6.7, so we get this message:

    DavidGriswoldeB_0-1613069621173.png

     

     



  • 45.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 16, 2021 09:08 PM

    It's been a couple of months and I am just getting back to this after getting our vCenters upgraded to 7.0. The command Get-VMGuestDisk is useful, but it does not appear to give the details of SCSI device or the VMDK's location in storage. It does contain a reference back to the VM object (VMGuest), but no clear way to like the GuestDisks to VMDKs, like a UID or objectID.



  • 46.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 16, 2021 09:37 PM

    Have a look at New Release – PowerCLI 12, that explains how the link works.



  • 47.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 19, 2021 03:40 PM

    Thanks for the reply, but it is still not working for me. Here is what I am working with:

    PowerCLI 12.2
    VMware Tools 11.2.97 installed on the target VM
    vCenter 7.0.1

    when I run the commands, this is what I get:

    DavidGriswoldeB_0-1618846797168.png

     



  • 48.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 19, 2021 04:06 PM

    The error is clear, that VM doesn't provide the Guest DIsk mapping.
    That would mean one of the requirements for this to work is not met.



  • 49.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 19, 2021 05:09 PM

    Thank you for the RTFM response, and I am mostly kidding. I thought I had provided all the required info to show that I had already double-checked the prerequisites listed here. I did notice that the VM was still on an old version of virtual hardware, and upgraded it to v15. However, I am still getting the same results. I even checked the Developer Documentation on the command and found nothing additional. Any suggestions? 



  • 50.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 19, 2021 05:30 PM

    There are some more requirements, not all of them documented in the PowerCLI Reference.
    You might want to have a look at Cody's post What’s New in vSphere 7.0 Storage Part III: GuestInfo VirtualDiskMapping Linux, PowerCLI support

    He lists his conclusion at the end of the post.

     



  • 51.  RE: PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

    Posted Apr 19, 2021 09:01 PM

    Crap - my ESXi hosts are still on 6.7 and ESXi 7.0 is required. I didn't find that specific piece of info until I checked out Part II of Cody's post.

    I will move forward with my script that will work in both 6.7 and 7.0. It is not perfect because I am depending on the drives returned by Get-HardDrive to have been added in the same order they appear in the Get-VMGuestDisk. I will need to add some additional logic to verify.

     

    Thanks again!