Last active
July 15, 2020 17:43
-
-
Save broestls/0ab21c67f4938297c81fbdca6480d0f2 to your computer and use it in GitHub Desktop.
PowerCLI: Tagging vCenter Entities, Creates new Tags if they do not exist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Target to be tagged | |
$entity = "" | |
# Set the tags for your target here | |
# Empty quotes will not be set on target entity | |
$desired_tags = @{ | |
class = ""; | |
billing_owner = ""; | |
billing_owner_email = ""; | |
admin_owner = ""; | |
admin_owner_email = "" | |
} | |
# Test for existence or create new tag as needed | |
$tags = @{} | |
$desired_tags.getEnumerator() | foreach { | |
if ((Get-Tag -Category $_.key -Name $_.value) -eq $null) {New-Tag -Name $_.value -Category $_.key} | |
$tags.add($_.key, (Get-Tag -Category $_.key -Name $_.value)) | |
} | |
# Assign the tags to $entity | |
foreach ($t in $tags.Values) { | |
New-TagAssignment -Tag $t -Entity $entity | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment