VMware Cloud Community
schellh1
Contributor
Contributor

Powercli Tag comparison

Hello,

sorry to bother, my powershell is too bad.

we balanced our Veeam Backups with tags, now we want to automatically assign tags to new vm's. one part here would be to find out the sum of the disksizes of all vm's with the same tag.

Some examples what i have, but would not be suitable for a comparison for adding up. i dont know where to continue:

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> get-vm | where {({(Get-TagAssignment -Entity $_ )} | select @{N="Tag";E={((Get-TagAssignment -Entity $_ | select -ExpandProperty Tag).Name -join ",")}}) -eq ({get-tag -category 'Veeam Jobs' -Name VeeamJob4 | select @{N="Tag";E="Name"}})}

first part of the comparison would spit out this:

get-vm | Where{(Get-TagAssignment -Entity $_ )} | select @{N="Tag";E={((Get-TagAssignment -Entity $_ | select -ExpandProperty Tag).Name -join ",")}}

Tag

---

VeeamJob2

VeeamJob2

second part this:

get-tag -category 'Veeam Jobs' -Name VeeamJob2 | select @{N="Tag";E="Name"}

Tag

---

VeeamJob2

why cant i compare these with match or equals ?

I guess there are far better methods of getting what i want ? Maybe one can help.

I would enclose this comparison with the function  [math]::Round(((                                 .UsedSpaceGB | measure-Object -Sum).Sum)

So i hoped to get the Disksize sums of all vm's with the particular tag.

After that, i would define somewhere which tags are for linux and which for windows vm's, get that value and assign a tag where no is assigned . pretty hard for me noob :smileysilly:

3 Replies
LucD
Leadership
Leadership

Try something like this

$tagCategory = 'Veeam Jobs'

$cat = Get-TagCategory -Name $tagCategory

Get-VM | Get-TagAssignment -Category $cat | Group-Object -Property {$_.Tag.Name} | %{

    New-Object PSObject -Property ([ordered]@{

        Tag = $_.Name

        VMDKTotal = $_.Group.Entity.UsedSpaceGB | Measure-Object -Sum | select -ExpandProperty Sum

    })

}


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

schellh1
Contributor
Contributor

Hello,

thanks for the answer, looks useful. however, i noticed this before but did not tell, my 5.5 powercli 64 bit is missing get-tagcategory ?! any ideas in that matter ?

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-TagCategory

Get-TagCategory : Die Benennung "Get-TagCategory" wurde nicht als Name eines

Cmdlet, einer Funktion, einer Skriptdatei oder eines ausführbaren Programms

erkannt. Überprüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt

ist (sofern enthalten), und wiederholen Sie den Vorgang.

In Zeile:1 Zeichen:1

+ Get-TagCategory

+ ~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (Get-TagCategory:String) [], Com

   mandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

0 Kudos
LucD
Leadership
Leadership

Yes, that matters.

Is there any reason you stay with 5.5?

If not, upgrade to 6.3R1


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

0 Kudos