Add Custom Attribute to VMWare VM


I’m looking for some help to fine my attempt to write a quick PowerShell script when using PowerCLI connected to my firms VMWare cluster.

I’m looking to get a list of all Virtual Machines that are domain joined, list by GuestOS type i.e. Windows and then add a label to an existing Custom Attribute.

So far this is what i have come up with to list the VMs.

(Get-VM).where{$_.PowerState -eq ‘PoweredOn’
-and $.Guest.OSFullName -match ‘Windows’}

I’ll need to add a write to everyhost where Guess.OSFullName is Windows with a named label to the Custom Attribute called xyz.

Welcome to the forum. :wave:t4:

But when you are actually filtering for only VMs with the desired OS name all the VMs in the output will have the same label?! :man_shrugging:t4:

Anyway - an easy way to add an additional property is to use a calculated property:

BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

This thread can be closed. I resolved the issue.

Would you like to share your solution with the world? :wink: