I’ve spent enough hours working with VMware support, API folks, and Tagging team where I just need to share this for everyone. The more voices going to VMware about Tagging and vSphere/vRops performance, the faster a solution will be created.

The following Script is extremely rough. You can Edit the connection strings to be more secure with a $cred = get-credential etc. I made it extremely simple so each step can be validated within logs for performance testing.

The Script will :
1 – Connect to vcenter using VIServer and CISServer methods.
2 – Create ten Tag Categories
3 – Create 500 Random String tags within those tag categories
4 – Create a very simply VM template
5 – Clone that template across your test hosts.
6 – Finally, randomly assign a single tag from each category to every VM.

#######Connect to vCenter
connect-viserver “vcenter” -username “administrator@vsphere.local” -pass “**”
connect-cisserver “vcenter” -username “administrator@vsphere.local” -pass “**”
####### Create some tag categories:
new-TagCategory -name “cat1” -entityType “VMHost”,”VirtualMachine” -confirm:$false
new-TagCategory -name “cat2” -entityType “VMHost”,”VirtualMachine” -confirm:$false
new-TagCategory -name “cat3” -entityType “VMHost”,”VirtualMachine” -confirm:$false
new-TagCategory -name “cat4” -entityType “VMHost”,”VirtualMachine” -confirm:$false
new-TagCategory -name “cat5” -entityType “VMHost”,”VirtualMachine” -confirm:$false
new-TagCategory -name “cat6” -entityType “VMHost”,”VirtualMachine” -confirm:$false
new-TagCategory -name “cat7” -entityType “VMHost”,”VirtualMachine” -confirm:$false
new-TagCategory -name “cat8” -entityType “VMHost”,”VirtualMachine” -confirm:$false
new-TagCategory -name “cat9” -entityType “VMHost”,”VirtualMachine” -confirm:$false
new-TagCategory -name “cat10” -entityType “VMHost”,”VirtualMachine” -confirm:$false
####### Create 500 tags per category — total of 5,000 Tags
$allCateMethod = Get-CisService com.vmware.cis.tagging.category
$allcate = $allcateMethod.list()
$cates = @()
foreach ($cate in $allcate) {
$cates += $allCateMethod.Get($cate)
}
$cates = $cates | where {$_.name -match “cat”}

$alltagMethod = Get-CisService com.vmware.cis.tagging.tag
foreach($a in $cates){
$x = 0

while($x -lt 500){
$spec = $alltagMethod.Help.create.create_spec
$spec.name = (-join ((65..90) + (97..122) | Get-Random -Count 30 | % {[char]$_}))
$spec.description = “”
$spec.category_id = $a.id.value
$alltagMethod.Create($spec)
$x++
}
}
#######Create your VM Template: – Basic VM then delete the harddisk to reduce need for Datastore space.
$ahost = get-vmhost “vmhost1”
$adatastore = $ahost | get-datastore | sort freespaceGB -desc | select -f 1

new-vm -name “zTagTesterTemplate” -vmhost $ahost -datastore $adatastore -memoryGB “0.004” -confirm:$false -runasync
$avm = get-vm “zTagTesterTemplate”
$avm | get-harddisk| remove-harddisk -DeletePermanently -confirm:$false
$avm | set-vm -totemplate -confirm:$false
$thetemplate = get-template -name “zTagTesterTemplate”

#######Create a bunch of VMs… Thread this to as many hosts as you want… Going Serial here because I dont know your lab…
####### uncomment the new-vm command below to select the best for your lab…
####### I suggest using four to six ESXi hosts because of vSphere config limitation of VMs per host…
####### edit the MaxCount to match your host count… four hosts – 4,000 VMs… six hosts, 6,000 VMs…
####### 1000 is configured below if you are testing with one host….
####### I tested with 5,600 VMs to exaggerate the impact/results within vRops. “Bigger impact on the charts”
####### Only used if you want to create more than 1000 VMs and want to thread them across more hosts.
#######$hostlist = get-cluster | get-vmhost
####### Vars taken from above… edit if you want to change it here….
#######$ahost = get-vmhost “vmhost1”
#######$adatastore = $ahost | get-datastore | sort freespaceGB -desc | select -f 1
#######$thetemplate = get-template -name “zTagTesterTemplate”

$count = 0
$maxcount = 1000
$vmnamePrefix = “zTagTester”
while ($count -lt $maxcount){
$vmname = $vmnamePrefix + $count
#######New-vm -Name $vmname -VMhost ($hostlist | get-random) -Template $thetemplate -Datastore (get-datastore | sort freespaceGB -desc | select -f 1) -runAsync
New-vm -Name $vmname -VMhost $ahost -Template $thetemplate -Datastore $adatastore -runAsync
$count = $count + 1
}

#######Assign Tags to your VMs… I suggest looking at vRops at this time and watch as these commands run.
####### I’m populating the tag vars first because the tagging API could stop responding later for a slower get and set call.

$tag1 = get-tagcategory | where {$_.name -eq “cat1”} | get-tag
$tag2 = get-tagcategory | where {$_.name -eq “cat2”} | get-tag
$tag3 = get-tagcategory | where {$_.name -eq “cat3”} | get-tag
$tag4 = get-tagcategory | where {$_.name -eq “cat4”} | get-tag
$tag5 = get-tagcategory | where {$_.name -eq “cat5”} | get-tag
$tag6 = get-tagcategory | where {$_.name -eq “cat6”} | get-tag
$tag7 = get-tagcategory | where {$_.name -eq “cat7”} | get-tag
$tag8 = get-tagcategory | where {$_.name -eq “cat8”} | get-tag
$tag9 = get-tagcategory | where {$_.name -eq “cat9”} | get-tag
$tag10 = get-tagcategory | where {$_.name -eq “cat10”} | get-tag

$allvms = get-vm | where {$_.name -match “ztagtester”}

####### using counter to show where you are in the assignment.
####### I Thread this into different powershell windows because the API is a bit slow using New-tagassignment. (could try cisserver assignment methods in your lab)
$count = 0
foreach($avm in $allvms){
$avm | new-tagassignment -tag ($tag1|get-random)
$avm | new-tagassignment -tag ($tag2|get-random)
$avm | new-tagassignment -tag ($tag3|get-random)
$avm | new-tagassignment -tag ($tag4|get-random)
$avm | new-tagassignment -tag ($tag5|get-random)
$avm | new-tagassignment -tag ($tag6|get-random)
$avm | new-tagassignment -tag ($tag7|get-random)
$avm | new-tagassignment -tag ($tag8|get-random)
$avm | new-tagassignment -tag ($tag9|get-random)
$avm | new-tagassignment -tag ($tag10|get-random)
$count++
$count
}

####### Would be nice if new-tagassignment accepted an array of tags…
####### get a single VM and check if it has ten tags assigned….
get-vm ($allvms | select -f 1) | get-tagassignment

#######END – Check vrops collection cycle.