Introduction
Tags and custom attributes bring metadata structure to your VMware environment. Whether you’re classifying workloads, enforcing policies, or generating reports, PowerCLI enables full automation of tag and attribute management.
In this article, you will learn how to:
- Create and organize tag categories
- Assign tags to VMs, hosts, and other objects
- Query tags for filtering and automation
- Manage custom attributes and annotations
- Export tag metadata for documentation
My Personal Repository on GitHub
Understanding Tags vs Custom Attributes
| Feature | Tags | Custom Attributes |
|---|---|---|
| Scope | Flexible across object types | Typically for VMs only |
| Organization | Category-based | Key-value attached directly |
| Use Cases | Backup policies, app tiering, audit | Build info, cost centers, notes |
| Automation Ready | Yes (Get-Tag, New-TagAssignment) | Yes (Get-CustomAttribute) |
Tag Management with PowerCLI
Create a Tag Category
New-TagCategory -Name "ApplicationType" -Cardinality Single -EntityType VirtualMachine
Create Tags Inside the Category
New-Tag -Name "WebApp" -Category "ApplicationType"
New-Tag -Name "Database" -Category "ApplicationType"
Assign a Tag to a VM
$vm = Get-VM -Name "SQL01"
$tag = Get-Tag -Name "Database"
New-TagAssignment -Entity $vm -Tag $tag
List Tags for a VM
Get-VM -Name "SQL01" | Get-TagAssignment
Bulk Tag Assignment Using Filters
Tag all VMs in a folder or matching pattern.
$tag = Get-Tag -Name "WebApp"
Get-Folder -Name "Web Servers" | Get-VM | New-TagAssignment -Tag $tag
Or based on guest OS:
Get-VM | Where-Object {$_.Guest.OSFullName -like "*Ubuntu*"} | New-TagAssignment -Tag "Linux"
Exporting Tag Assignments to CSV
Get-VM | ForEach-Object {
$vm = $_
Get-TagAssignment -Entity $vm | Select-Object @{N="VM";E={$vm.Name}}, Tag, Category
} | Export-Csv -Path "C:\Reports\VM_Tags.csv" -NoTypeInformation
Managing Custom Attributes
List Existing Attributes
Get-CustomAttribute
Create a New Attribute
New-CustomAttribute -Name "Owner" -TargetType VirtualMachine
Set Value on a VM
Set-Annotation -Entity (Get-VM -Name "SQL01") -CustomAttribute "Owner" -Value "TeamA"
Report Custom Attribute Values
Get-VM | Select Name, @{N="Owner";E={($_ | Get-Annotation | Where-Object {$_.Name -eq "Owner"}).Value}}
Diagram: Tag and Attribute Automation

Use Case: Backup Classification by Tag
You can tag VMs as Daily, Weekly, or Excluded and use backup tools to process workloads accordingly.
Assign tag:
New-TagAssignment -Entity (Get-VM -Name "AppServer01") -Tag "Daily"
Backup solutions like Veeam, Commvault, and Rubrik can query vCenter tags to dynamically build protection groups.
Troubleshooting
| Issue | Fix |
|---|---|
| Tag assignment fails | Verify category entity type matches object (e.g., VM vs host) |
| Duplicate tags or categories | Use Get-Tag and Get-TagCategory to confirm uniqueness |
| Cannot read custom attribute value | Use Get-Annotation and filter on .Name explicitly |
| Attribute not visible in vCenter UI | Restart vSphere Client or verify access permissions |
What’s Next
Next article will focus on:
- Generating compliance and health reports using PowerCLI
- Scheduling reports for VM state, orphaned snapshots, and configuration drift