2 Replies Latest reply on Jan 12, 2011 10:40 AM by mattboren

    Need help with datastore script

    peter79 Enthusiast

      Guys,

       

      I currently have a script that looks for all datatstores that contain C1 and outputs the m to a csv file

       

      Get-Datastore *C1*| Select-Object name, FreeSpaceMB, CapacityMB | Export-Csv -NoTypeInformation c:\myDaterstoreInfo.csv

       

      The only problem is I would like to convert the free spcace and capacity measurements into GB.  I know there is a way I can do the conversion within the script but I forget how.  Could someone help me out?

       

      Thanks.


        • 1. Re: Need help with datastore script
          mattboren Master
          vExpert

          Greetings, @peter79-

           

          To do so you can change the "Select-Object" portion of the pipeline to used calculated properties as such:

          Select-Object Name,@{n="FreeSpaceGB"; e={$_.FreeSpaceMB / 1kb}},@{n="CapacityGB"; e={$_.CapacityMB / 1kb}}
          

           

          Enjoy

          • 2. Re: Need help with datastore script
            mattboren Master
            vExpert

            ...or, if you want to round those values a bit instead of having lots of decimal places, you can use the string formatting operator like:

            Select-Object Name,@{n="FreeSpaceGB"; e={"{0:n1}" -f ($_.FreeSpaceMB / 1kb)}},@{n="CapacityGB"; e={"{0:n1}" -f ($_.CapacityMB / 1kb)}}
            

             

            Depends on the precision you desire, of course.