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
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
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
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
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?