VMware Cloud Community
IKirill
Enthusiast
Enthusiast
Jump to solution

Get SUM of VCPU from vms array

Hi!

How i can get sum of VCPU of vms from array?

Whats wrong in my script?

$newvms = @(

"myvm01",

"myvm02"

)

Foreach ($newvm in $newvms) {

$report = Get-VM | ? name -Like $newvms*

}

$report | Measure-Object numcpu -Sum

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do

Get-VM  | where{$_.Name -like "myvm*"}

or

Get-VM | where {$newvms -contains $_.Name}


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

You are overwriting $report each time.

Since Get-VM accepts an array on the Name parameter, you can do

$newvms = @(

"myvm01",

"myvm02"

)

Get-VM -Name $newvms |

Measure-Object -Property NumCpu -Sum


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

0 Kudos
IKirill
Enthusiast
Enthusiast
Jump to solution

Thx LUCD!

But what about if i wont to use:

-Like $newvms* 

?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do

Get-VM  | where{$_.Name -like "myvm*"}

or

Get-VM | where {$newvms -contains $_.Name}


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

0 Kudos