VMware Cloud Community
Mr_G_Grant
Enthusiast
Enthusiast
Jump to solution

Create Table

Hi Guy's

I'm trying to create a table in PowerShell that displays VM system details from a supplied csv. The out put should be something like the below.

VM NAME               NUMCPU              MEM

System1                        4                     2048

System2                        1                     2048

System3                        1                     2048

Can anybody advise?

Any links to blogs explaining this would also be appreciated.

Kind Regards

Mr G

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

To read the names of the VMs from a CSV file you use the Import-Csv cmdlet.

The CSV file should look like this

vmName

VM1

VM2

VM3

The code could look like this

Get-VM -Name (Import-Csv C:\vmnames.csv -UseCulture | Select -ExpandProperty vmName) | 
Select
Name,NumCpu,MemoryGB |
Export-Csv
C:\report.csv -NoTypeInformation -UseCulture


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

View solution in original post

0 Kudos
3 Replies
vlife201110141
Enthusiast
Enthusiast
Jump to solution

connect-VIServer -server 'xxx' -username 'xxx' -password 'xxx'
$report = @()
$vms = Get-VM
foreach($vm in $vms){
$row = "" | select VMName, NumCPU, Memory
$row.VMName = $vm.name
$row.NumCPU = $vm.NumCPU
$row.Memory = $vm.MemoryMB
$report += $row
}
$report | Export-Csv "C:\export.csv" -NoTypeInformation -UseCulture

LucD
Leadership
Leadership
Jump to solution

To read the names of the VMs from a CSV file you use the Import-Csv cmdlet.

The CSV file should look like this

vmName

VM1

VM2

VM3

The code could look like this

Get-VM -Name (Import-Csv C:\vmnames.csv -UseCulture | Select -ExpandProperty vmName) | 
Select
Name,NumCpu,MemoryGB |
Export-Csv
C:\report.csv -NoTypeInformation -UseCulture


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

0 Kudos
Mr_G_Grant
Enthusiast
Enthusiast
Jump to solution

This appears to be close. I modified your script a bit so

$vms = Get-VM

becomes

$vms = Get-Content -path (some location.csv)

Which resulted in a blank csv file with only the headings. Any other ideas?

0 Kudos