Need some help with vmware powershell VM disks report.

Welcome Forums General PowerShell Q&A Need some help with vmware powershell VM disks report.

This topic contains 3 replies, has 4 voices, and was last updated by

9 months, 3 weeks ago.

  • Author
  • #121914

    Topics: 12
    Replies: 20
    Points: 61
    Rank: Member

    Hi All,

    I have powershell that lists VM name and its subsequent vmdk files along with datastore name. I need to add Get-VM's property UsedSpaceGb in the report.

    $VMsAdv = Get-VM | Sort-Object Name | % { Get-View $_.ID }
    $myCol = @()
    ForEach ($VMAdv in $VMsAdv)
    ForEach ($Disk in $VMAdv.Layout.Disk)
    $myObj = "" | Select-Object Name, Disk
    $myObj.Name = $VMAdv.Name
    $myObj.Disk = $Disk.DiskFile[0]
    $myCol += $myObj

    At present the report looks like below

    Name                         Disk

    VMname                   [Datastorename] VMName_1.vmdk

    I would like it to be with VMName, Datastorename, Vmdk file name and Storage used by VMdk file  in the report. Can anybody help me ?

  • #121923

    Topics: 24
    Replies: 671
    Points: 1,564
    Helping Hand
    Rank: Community Hero

    Is there some way you can do "Get-VM | export clixml vm.xml" and share the vm.xml? A lot of people probably don't have the get-vm command.

  • #121942

    Senior Moderator
    Topics: 8
    Replies: 1009
    Points: 3,281
    Helping Hand
    Rank: Community Hero

    You can do it in a oneliner.

    Get-VM | Select-Object -Property Name,@{E={([array]$_.HardDisks.filename)[0]};l='Disk'},UsedSpaceGB
  • #121957

    Topics: 12
    Replies: 231
    Points: 461
    Helping Hand
    Rank: Contributor

    If I remember correctly some attributes are only populated if and while VMTools are running.

    I'm going to be so boring and suggest that you google for it.
    Not to be mean or dismissive but depending on what you're looking for it can be quite a long answer.
    With a quick google I found multiple posts on vmware forum and blog posts elsewere.

The topic ‘Need some help with vmware powershell VM disks report.’ is closed to new replies.