I've seen a lot of confusion around tagging VMs via PowerCLI-especially when using New-TagAssignment.
If you pass a VM name string directly like -Entity "vmname", it will fail because -Entity expects a VM object, not a string.
You have two clean options:
1- Pipe the VM object directly:
Get-VM -Name "vmname" | New-TagAssignment -Tag $tag
2- Assign the VM object to a variable first:
$vm = Get-VM -Name "vmname"
New-TagAssignment -Tag $tag -Entity $vm
Both approaches ensure you're passing the correct object type to New-TagAssignment. Hope this clears things up!
-------------------------------------------