VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Join VM info with external info

I need to take an existing spreadsheet with a list of VM names, merge information from vCenter with it, and create a new csv that I can open in Excel.

For example, my existing spreadsheet looks like this:

nameLocationOwner
Hostname1NYBob
hostname2LAJoe
hostname3DCBill

then, I have powercli script that does this:

get-vm | select name, numcpu, memoryGB

The "Name" field in my spreadsheet is equivalent to the "name" field in vCenter.  How can I create a csv that has the info both from vCenter and the spreadsheet for each VM?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

$report = foreach($row in Import-Csv -Path vmnames.csv -UseCulture){

    Get-VM -Name $row.name |

    Select Name,NumCpu,MemoryGB,

        @{N='Location';E={$row.Location}},

        @{N='Owner';E={$row.Owner}}

}

$report | Export-Csv -Path newreport.csv -NoTypeInformation -UseCulture


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

View solution in original post

0 Kudos
3 Replies
bayupw
Leadership
Leadership
Jump to solution

Could you change your column name from 'name' to 'VMName' so it doesn't conflict?

Or you also could do 2 sheets and the third sheet will have a combined spreadsheet using function like VLOOKUP VLOOKUP function - Office Support

Bayu Wibowo | VCIX6-DCV/NV
Author of VMware NSX Cookbook http://bit.ly/NSXCookbook
https://github.com/bayupw/PowerNSX-Scripts
https://nz.linkedin.com/in/bayupw | twitter @bayupw
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$report = foreach($row in Import-Csv -Path vmnames.csv -UseCulture){

    Get-VM -Name $row.name |

    Select Name,NumCpu,MemoryGB,

        @{N='Location';E={$row.Location}},

        @{N='Owner';E={$row.Owner}}

}

$report | Export-Csv -Path newreport.csv -NoTypeInformation -UseCulture


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

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

ok thanks again

0 Kudos