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

 
Participant
1 month ago.

  • Author
    Posts
  • #121914

    Participant
    Points: 12
    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
    }
    }
    $myCol
    
    

    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
    js

    Participant
    Points: 315
    Helping Hand
    Rank: Contributor

    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

    Participant
    Points: 814
    Helping Hand
    Rank: Major Contributor

    You can do it in a oneliner.

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

    Participant
    Points: 190
    Helping Hand
    Rank: Participant

    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.

You must be logged in to reply to this topic.