I have a CSV with the following content:
vmname,oldtag,newtag
vmname - is the affected VM
oldtag - tag to be removed
newtag - Tag which should be added (is available in the vCenter)
Import-Csv -path "filepath" | ForEach-Object {
Remove-TagAssignment (Get-VM $($_.vmname) | Get-TagAssignment -Category $($_.oldtag)) -Confirm:$false
New-TagAssignment -Tag "$($_.newtag)" -Entity "$($_.vmname)" -Confirm:$false
}
Message in PowerCLI:
Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
Without CSV it works for individual vm
Remove-TagAssignment (Get-VM Servername | Get-TagAssignment -Category "Prod") -Confirm:$false
New-TagAssignment -Tag "Test" -Entity Servername -Confirm:$false
Someone an idea?
Thanks
Ciao
I tried your script and in my environment it running without problem.
I used this CSV format
But you need to use for oldtag not the specific TAG but the category.
If you want to remove a specific TAG (not Category) you need to change this row (replace -Category with -Tah)
Remove-TagAssignment (Get-VM $($_.vmname) | Get-TagAssignment -Tag $($_.oldtag)) -Confirm:$false
For your specific error can you post your CSV? Do you have any blank rows?
Hi @fabio1975
thank you in advance for your help.
My .csv
The hint with the CSV got me further.
Just tested with the "," and it seems to work better