PowerCLI

 View Only
  • 1.  Powercli - get Harddisk and compare with OS Drive Letter on Guest

    Posted Jul 12, 2024 08:18 AM

    Hi there,

    we have the snippet:

    $VM = "VMNAME"
    $result = Get-VM $VM | Get-HardDisk |
        Select-Object `
        @{N="SCSI ID"; E={$strControllerKey = $_.ExtensionData.ControllerKey.ToString(); "{0}`:{1}" -f $strControllerKey[$strControllerKey.Length - 1], $_.ExtensionData.Unitnumber}},
        @{N='vDisk Name'; E={$_.Name}},
        @{N='vDisk Capacity'; E={$_.CapacityGB}},
        @{N='Disk Type'; E={$_.DiskType}},
        @{N='OS Drive Letter'; E={Get-VMGuestDisk -VM $VM | Select-Object -ExpandProperty DiskPath}}
     
    $result | Format-Table -AutoSize

    Now the Problem is that the OS Drive letter is not combined to the SCSI ID. I always get an Array with Drive Letters.

    Sometimes we get requests from customers to resize disks on VMs and they give us drive letters or other stuff we cannot work with, if there are drives with the same size, so we thought it would be cool to have a script to get the job done. The problem is: we don't have the credentials for the VMs most of the time.

    Can anybody give me a hint how to solve that problem?

    Thanks in advance

    regards

    Susie



  • 2.  RE: Powercli - get Harddisk and compare with OS Drive Letter on Guest

    Posted Jul 12, 2024 09:03 AM

    As I mentioned multiple times, there is no foolproof method to match VMDK to Guest OS partitions.

    If you have the correct VMware Tools version installed, the best option is to use the Get-VMGuestDisk cmdlet.



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


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


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