VMware Cloud Community
TheVMinator
Expert
Expert

General Format for Listing VM properties

I am wanting to create some lists based on calculations on properties of VMs

.  For example:

Do a get-vm to get a list of VMs.

For each VM, calculate

certain characteristics that are not part of the VMs native properties.  For example, the amount of currently configured RAM + 2GB and the current  amount of disk +10GB

When I open the csv in Excel later

it should look like this:

NameCurrent RAM + 2GB would beCurrrent Disk + 10 GB Would Be
vm16GB80GB
vm210GB50GB
vm38GB60GB

Suppose I am creating an array to store the information that will be writting to csv.

In this context

what are the constructs involved:

For example:

  • An Array holds everything that will be written to the csv.

     Within that array:

  • Each VM with its calculated values represents an object in the array

  • Each calculated value such as 4GB RAM becomes an object property, it just isn't one of the properties native to the VM object

Is this correct?

What would this code look like?

Thanks!

0 Kudos
1 Reply
LucD
Leadership
Leadership

There is not really a need to use an array for this, you can use calculated properties and then pass the objects over the pipeline to the Export-Csv cmdlet.

Something like this

Get-VM |
Select Name,
   
@{N="Current RAM + 2GB";E={$_.MemoryGB + 2}},
   
@{N="Currrent Disk + 10 GB";E={[math]::Round($_.UsedSpaceGB + 10,2)}} |
Export-Csv c:\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos