VMware Cloud Community
dsstaomri
Contributor
Contributor
Jump to solution

Need help gathering CPU and RAM info

Hi All,

I have the following, working, script that outputs VM names and the full folder hierarchy they're in.  I need to add detail for vCPU count and Memory.  Can you help?

$report = @()

Get-VM | Get-View | %{

  $row = "" | select Name, Path

  $row.Name = $_.Name

  $current = Get-View $_.Parent

  $path = $_.Name

  do {

    $parent = $current

     if($parent.Name -ne "vm"){$path =  $parent.Name + "\" + $path}

     $current = Get-View $current.Parent

  } while ($current.Parent -ne $null)

  $row.Path = $path

  $report += $row

}

$report

Thanks,

DS

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this, I optimised the script a bit for speed.

$report = @()

Get-View -ViewType VirtualMachine -Property Name,Parent,Config.Hardware | %{

  $row = "" | select Name, Path, vCPU, MemoryMB

  $row.Name = $_.Name

  $current = Get-View $_.Parent -Property Name,Parent

  $path = $_.Name

  do {

    $parent = $current

     if($parent.Name -ne "vm"){$path =  $parent.Name + "\" + $path}

     $current = Get-View $current.Parent -Property Name,Parent

  } while ($current.Parent -ne $null)

  $row.Path = $path

  $row.vCPU = $_.Config.Hardware.NumCPU

  $row.MemoryMB = $_.Config.Hardware.MemoryMB

  $report += $row

}

$report


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this, I optimised the script a bit for speed.

$report = @()

Get-View -ViewType VirtualMachine -Property Name,Parent,Config.Hardware | %{

  $row = "" | select Name, Path, vCPU, MemoryMB

  $row.Name = $_.Name

  $current = Get-View $_.Parent -Property Name,Parent

  $path = $_.Name

  do {

    $parent = $current

     if($parent.Name -ne "vm"){$path =  $parent.Name + "\" + $path}

     $current = Get-View $current.Parent -Property Name,Parent

  } while ($current.Parent -ne $null)

  $row.Path = $path

  $row.vCPU = $_.Config.Hardware.NumCPU

  $row.MemoryMB = $_.Config.Hardware.MemoryMB

  $report += $row

}

$report


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

0 Kudos
dsstaomri
Contributor
Contributor
Jump to solution

This could not have worked better.  Thank you for the help, and Happy Holidays!

0 Kudos