Here's my script....
$myCol = @()
foreach ($cluster in Get-Cluster)
{
foreach($vmhost in ($cluster | Get-VMHost))
{
foreach($vm in (Get-VM -Location $vmhost)){
$VMView = $vm | Get-View
$VMSummary = "" | Select ClusterName,VMName,MemorySize,VMSockets,VMCores
$VMSummary.ClusterName = $cluster.Name
$VMSummary.VMName = $vm.Name
$VMSummary.MemorySize = $VMView.Hardware.Config.MemorySize / 1024
$VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu
$VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket
$myCol += $VMSummary
}
}
}
$myCol | Export-Csv C:\Temp\Test.txt
The column "MemorySize" is returning 0 for all VM's...
"DMZ","Trend Micro Deep Security (1)","0","2","1"
"DMZ","Guest Introspection (1)","0","2","1"
Any ideas?
I didn't include that line.
This is the complete revised script
foreach ($cluster in Get-Cluster)
{
foreach($vmhost in ($cluster | Get-VMHost))
{
foreach($vm in (Get-VM -Location $vmhost)){
$VMView = $vm | Get-View
$VMSummary = "" | Select ClusterName,VMName,MemoryMB,VMSockets,VMCores,VMvCPU
$VMSummary.ClusterName = $cluster.Name
$VMSummary.VMName = $vm.Name
$VMSummary.MemoryMB = $VMView.Config.Hardware.MemoryMB
$VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu/$VMView.Config.Hardware.NumCoresPerSocket
$VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket
$VMSummary.VMvCPU = $VMView.Config.Hardware.NumCpu
$myCol += $VMSummary
}
}
}
$myCol | Export-Csv C:\Temp\VM-cpu-core.txt
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There is no MemorySize property in a VirtualHardware object.
It's called MemoryMB.
Your line could be
$VMSummary.MemorySizeMB = $VMView.Hardware.Config.MemoryMB
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That still gets me a "0".
If I take out the "/ 1024" I get a Null value.
I didn't include that line.
This is the complete revised script
foreach ($cluster in Get-Cluster)
{
foreach($vmhost in ($cluster | Get-VMHost))
{
foreach($vm in (Get-VM -Location $vmhost)){
$VMView = $vm | Get-View
$VMSummary = "" | Select ClusterName,VMName,MemoryMB,VMSockets,VMCores,VMvCPU
$VMSummary.ClusterName = $cluster.Name
$VMSummary.VMName = $vm.Name
$VMSummary.MemoryMB = $VMView.Config.Hardware.MemoryMB
$VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu/$VMView.Config.Hardware.NumCoresPerSocket
$VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket
$VMSummary.VMvCPU = $VMView.Config.Hardware.NumCpu
$myCol += $VMSummary
}
}
}
$myCol | Export-Csv C:\Temp\VM-cpu-core.txt
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you sir!