5 Replies Latest reply on Nov 12, 2016 10:53 PM by LucD

    get-vm and hard disk

    tdubb123 Master

      Trying to get a list of VMs and their hard disk (vmdk ) sizes and USedspace and provisioned space

       

      get-content vm.txt | % {get-vm $_* | Get-HardDisk | select Parent, Name, CapacityGB } | ft -AutoSize

       

       

      this works but how do I get the Usedspace and provisoned space as well?

        • 1. Re: get-vm and hard disk
          tdubb123 Master

          any idea why I am only getting one line in my csv?

           

           

           

           

           

          PS C:\powershell> get-content vms.txt | %{ get-vm $_*  | Get-HardDisk | select PArent, NAme, CapacityGB } | Export-Csv C:\powershell\vm_diskinfo2.csv

          • 2. Re: get-vm and hard disk
            vXav Hot Shot
            vExpert

            At each loop you overwrite the content of the CSV. Try adding -Append to your Export-CSV.

             

            For the guest used space you can find it in (get-vm).Guest.Disks but to do the link with the actual hard disk you need to interact with the guest OS.

             

            Check this post : PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?

            • 3. Re: get-vm and hard disk
              tdubb123 Master

              how do I combine

               

              NAme, hard disk 1, hard disk 2, provisionedspacedb and usedspacegb?

              • 4. Re: get-vm and hard disk
                tdubb123 Master

                when I look at my VM, I see this with get-harddisk

                 

                Screen Shot 2016-11-11 at 1.07.05 PM.png

                 

                but get-vm shows this for Provisionedspacegb

                 

                Screen Shot 2016-11-11 at 1.07.58 PM.png

                 

                why isnt it 50gb instead ? where is 54.9 coming from?

                • 5. Re: get-vm and hard disk
                  LucD Guru
                  Community WarriorsvExpertUser Moderators

                  ProvisionedSpaceGB is the total of all the used storage space by the VM, not only the HardDisk space.

                  This number includes the VMX, the swap file, the logs...

                   

                  You can do something like this, but the Provisioned and Used is only maintained per VM, not per harddisk.

                  To get the provisioned and used per datastore, you will have to actually look at the files that constitute a harddisk.

                   

                  Note that the Export-Csv takes the first element in an array to determine how many columns there will be in the CSV, hence the descending sort per number of properties, before the export.

                   

                   

                  $report = Get-VM | %{

                      $obj = New-Object PSObject -Property @{

                          VM = $_.Name

                          ProvisionedGB = $_.ProvisionedSpaceGB

                          UsedGB = $_.UsedSpaceGB

                      }

                      $i = 1

                      Get-HardDisk -VM $_ | $%{

                          $obj | Add-Member -MemberType NoteProperty -Name "HD$($i)" -Value $_.CapacityGB

                          $i++

                      }

                      $obj

                  }

                   

                  $report | Sort-Object -Property {($_ | Get-Member -MemberType NoteProperty).Count} -Descending |

                  Export-Csv report.csv -NoTypeInformation -UseCulture

                   

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz