1 Reply Latest reply on Jul 17, 2008 10:21 PM by LucD

    Help with Creating Report

    ablej Hot Shot

      I am trying to use the following code to export VM hard disk size to a Excel file. The script is from the VI toolkit blog.

       

       

       

       

       

      $datastoreExp = @{N="Datastore"; E={ ($_ | get-datastore | select-object -first 1).Name }}

      $diskSizeExp = @{N="Total Disk"; E={ ($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum }}

      get-vm | select Name, $datastoreExp, $diskSizeExp | sort -property datastore,"Total Disk" -

       

       

       

       

       

       

       

      Any help is greatly appreciated

        • 1. Re: Help with Creating Report
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          Powershell has a handy cmdlet, called Export-Csv, that does exactly that.

          You pipe the results to this cmdlet, specify a filename and that's it.

           

          $datastoreExp = @{N="Datastore"; E={ ($_ | get-datastore | select-object -first 1).Name }}
          $diskSizeExp = @{N="Total Disk"; E={ ($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum }}
          get-vm | select Name, $datastoreExp, $diskSizeExp | sort -property datastore,"Total Disk" | Export-Csv c:\test.csv
          

           

          The beauty of Powershell

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