VMware Cloud Community
TheFortune
Contributor
Contributor

Get and remove Tags of specific VMs from CSV

Hello Everyone, 

I  have a task to remove tags of VMs that could reside in any of two vCenter servers and before I remove I have to get the list of current tags they have.  Something that could  collect the list of VMs from CSV and export with TAG info and I can run another script to remove Tags or may be both in one.

Thank you very much.  

0 Kudos
3 Replies
LucD
Leadership
Leadership

Just to make sure I get the question, you are looking for the Tags assigned to a specific set of VMs.
And these VMs are specified in a list (a CSV file ?), and can be sitting in 2 different vCenters.

Can a VM with the same name appear in both vCenters?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
TheFortune
Contributor
Contributor

Hi LucD, You are right, Thats exactly what I am looking for. And for the second question, the VM names are Unique and would never be the same. 

Thank you. 

0 Kudos
LucD
Leadership
Leadership

If your CSV file looks like this

Name

vm1

vm2

then you could do

Get-TagAssignment -Entity (Import-Csv -Path .\vmnames.csv -UseCulture).Name |

Select @{N='VM';E={$_.Entity.Name}},

  @{N='Category';E={$_.Tag.Category}},

  @{N='Tag';E={$_.Tag.Name}} |

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos