Hi,
I'm trying to tag multiple VM's in a large environment (thousands).
I'm hoping that I can read the contents of a csv and use PowerCLI to do the Tagging
cvs format would be
MyServer1,ApplicationNameXxxx
MyServer1,ApplicationNameBbbb
What I have so far is
$tc = New-TagCategory -Name "Application Name"
Get-Content -Path c:\VMTags.csv | ConvertFrom-Csv -Header VMname,Tag | foreach {
if (!(Get-Tag -Name $_.tag)) {
$t = $tc | New-Tag $_.tag
}
Get-VM -Name $_.VMname | New-TagAssignment -Tag $t -Confirm:$false
}
My intention is
- PowerCLI reads the csv file
- If the specified Tag does not exist already, it is created and assigned to the "Application Name" tag category
- The tag is then assigned to the VM
Thanks