VMware Cloud Community
Hemijimi
Contributor
Contributor

Add tag based on cpu and memory combination

I am trying to apply a tag based on a combination of cpu and memory. Here is what I have:

$mytag = Get-Tag -Name "Standard" 

$vmlist = get-vm | Where ($numcpu -le 2 -And $memoryGB -le 4)

foreach ($vm in $vmlist) { 

New-TagAssignment -Tag $Standard -Entity $vm 

I am getting no result from the $vmlist variable.

Thanks

0 Kudos
2 Replies
Hemijimi
Contributor
Contributor

Made some changes and here is where I am at:

$mytag = Get-Tag -Name "Standard" 

$vmlist = Get-VM | Where-Object { $_.numcpu -le 2 -and $_.memoryGB -le 4} Select Name

foreach ($vm in $vmlist) { 

New-TagAssignment -Tag $mytag -Entity $vm 

Now I am getting this error when the last line runs:

pastedImage_3.png

0 Kudos
Hemijimi
Contributor
Contributor

Never mind. Smiley Happy

Here is what worked:

$vmlist = Get-VM | Where-Object { $_.numcpu -le 2 -and $_.memoryGB -le 4}

foreach ($vm in $vmlist) { 

New-TagAssignment -Tag Standard -Entity $vm 

0 Kudos