VMware Cloud Community
COS
Expert
Expert
Jump to solution

Getting the value 0 for memory size

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?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I didn't include that line.
This is the complete revised 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,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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
COS
Expert
Expert
Jump to solution

That still gets me a "0".

If I take out the "/ 1024" I get a Null value.

Smiley Sad

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I didn't include that line.
This is the complete revised 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,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

0 Kudos
COS
Expert
Expert
Jump to solution

Thank you sir!

0 Kudos