Hello,
I have a file with correct tags of the environment (prod,test,dev). I need to read the VM name and tag from the file and if itsn't equal to the tag in vSphere change it. I wrote a script but I couldn't understand how to compare the data in file (string) with tag on VM which is not a string. Could you help me to fix my script?
$vmlist = Import-CSV 'C:\tools\change_tag_to_vm.csv' -Delimiter ";"
foreach ($item in $vmlist)
{
$vmname = $item.vmname #VMname
$env = $item.env #Environment vm_landscape tag
$oldtag=Get-TagAssignment -Category VM_Landscape -Entity $vmname
if ($oldtag -ne $env)
{
Remove-TagAssignment -tag $oldtag confirm:$false
New-TagAssignment -Tag $env -Entity $vmname
}
}
You could test like this
if ($oldtag.Tag.Name -ne $env)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could test like this
if ($oldtag.Tag.Name -ne $env)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD It works, thank you very much for help!
