Hi All,
I currently have a working script called 'VMtoCPU.ps1' that will collect information on resources used by VMs:
Get-VM |
ForEach-Object {
$Report = "" | sort -Descending NumCpu | Select-Object -property Name,NumCpu,MemoryMB,VMHost
$Report.Name = $_.Name
$Report.NumCpu = $_.NumCpu
$Report.MemoryMB = $_.MemoryMB
$Report.VMHost = $_.VMHost
Write-Output $Report
} | Export-Csv VMinf.csv -NoTypeInformation
Get-Content Vminf.csv | Foreach-Object {$_ -replace "`"", ""} | Set-Content TOUT.csv
Get-Content TOUT.csv | %{
$_.TrimEnd(',')
} | Set-Content VMinf.csv
Rob.
What I would like to do, is have a file called 'vCenterList.ini' listing a number of vCenter servers like this:
vCenters
vCenter-001
vCenter-002
vCenter-003
vCenter-004
vCenter-005
vCenter-006
...that I can read into the 'VmtoCPU.ps1' script, connect to each vCenter, run and append to the outputted csv file.
Any ideas folks?
Best,
Something like this should do that
$Report = @() foreach($vc in Import-Csv ./vCenterList.ini){ Connect-VIServer -Server $vc
Get-VM | ForEach-Object { $row = "" | Select-Object -property Name,NumCpu,MemoryMB,VMHost,VCenter
$row.VCenter = $vc
$row.Name = $_.Name
$row.NumCpu = $_.NumCpu
$row.MemoryMB = $_.MemoryMB
$row.VMHost = $_.VMHost
$Report += $row
} } $Report | Export-Csv VMinf.csv -NoTypeInformation
It assumes that the linkedmode is set to single and that you can connect with SSO to each of the vCenters in your list.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Something like this should do that
$Report = @() foreach($vc in Import-Csv ./vCenterList.ini){ Connect-VIServer -Server $vc
Get-VM | ForEach-Object { $row = "" | Select-Object -property Name,NumCpu,MemoryMB,VMHost,VCenter
$row.VCenter = $vc
$row.Name = $_.Name
$row.NumCpu = $_.NumCpu
$row.MemoryMB = $_.MemoryMB
$row.VMHost = $_.VMHost
$Report += $row
} } $Report | Export-Csv VMinf.csv -NoTypeInformation
It assumes that the linkedmode is set to single and that you can connect with SSO to each of the vCenters in your list.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference