2 Replies Latest reply on Mar 2, 2020 11:03 AM by Timjh

    Get Disk usage report using ExtensionData.Guest but not using ForEach clause

    Timjh Novice

      Hey all,

       

      I have an existing script that emails a table of all VMs along with some related data and I want to add several columns for VM storage to it but am running into issues I can't figure out. I found this one liner on virtu-al's that works perfectly but am having difficulty integrating that code into this existing script and don't want to change how it's designed to use "For Each" and want to keep it how it is, using the standard get-folder | get-vm to pull the data into a variable. Appreciate any assistance here.

       

      One-Liner that works great using extensiondata.guest

      ForEach ($VM in Get-VM ){($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},DiskPath, @{N="Capacity(MB)";E={[math]::Round($_.Capacity/ 1MB)}}, @{N="Free Space(MB)";E={[math]::Round($_.FreeSpace / 1MB)}}, @{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}

       

       

      My Code snippet thats not working

      $vmlist = Get-Folder $folder | Get-VM |

      select Name,

      @{N="IP Address";E={@($_.guest.IPAddress[0])}},

      @{N='Folder';E={$_.Folder.Name}},

      @{N="Capacity(MB)";E={[math]::Round($_.Extensiondata.Guest.Disks.Capacity/ 1MB)}},

      @{N="Free Space(MB)";E={[math]::Round($_.Extensiondata.Guest.Disks.FreeSpace / 1MB)}},

      @{N="Free Space %";E={[math]::Round(((100* ($_.Extensiondata.Guest.Disks.FreeSpace))/ ($_.Extensiondata.Guest.Disks.Capacity)),0)}}

       

       

       

      Thanks,

      Tim

        • 1. Re: Get Disk usage report using ExtensionData.Guest but not using ForEach clause
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          You have to tell how you would want to represent the results, especially if a VM's guest OS has more than 1 disk.

          Should the report have in that case have 1 row per disk?

          Or do you want all disks info in 1 row?

           

          Name | IP Address | ... | Disk1 Name | DiskPath1 | ...

          Name | IP Address | ... | Disk2 Name | DiskPath2| ...

          Name | IP Address | ... | Disk3 Name | DiskPath3 | ...

          or

           

          Name | IP Address | ... | Disk1 Name | DiskPath1 | ... | Disk2 Name | DiskPath2| ... | Disk3 Name | DiskPath3

          The 1st format is straightforward.

           

           

          $vmlist = Get-Folder $folder | Get-VM -PipelineVariable vm |

          Get-VMGuest | select -ExpandProperty Disks |

          Select @{N='VM';E={$vm.Name}},Path,

          @{N="IP Address";E={@($vm.guest.IPAddress[0])}},

          @{N='Folder';E={$vm.Folder.Name}},

          @{N="Capacity(MB)";E={[math]::Round($_.Capacity/ 1MB)}},

          @{N="Free Space(MB)";E={[math]::Round($_.FreeSpace / 1MB)}},

          @{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}}

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          1 person found this helpful
          • 2. Re: Get Disk usage report using ExtensionData.Guest but not using ForEach clause
            Timjh Novice

            LucD -

             

            This worked perfectly, Thanks!

             

            Regards,

            Tim