VMware Cloud Community
pamiller21
Enthusiast
Enthusiast
Jump to solution

Copy VM Tags From VMs

Is there a way to take the tags from <VM NAME> and copy them to <VM NAME>_replica?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I meant like this

Get-VM | Get-TagAssignment |
ForEach-Object -Process {
  New-TagAssignment -Entity "$($_.Entity.Name)_replica" -Tag $_.Tag
}


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

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

Yes


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

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

lol any advice on how to conquer this? I am at a loss on how to do this today.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Use the TagAssignment cmdlets.
Something like this for example.

$vmName = 'MyVM'
$copyVm = "$($vmName)_replica"

Get-VM -Name $vmName | Get-TagAssignment |
ForEach-Object -Process {
  New-TagAssignment -Entity $copyVm -Tag $_.Tag
}


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

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

That is simple, can I point this at all my VMs and somehow array through all them?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, just leave out the Name parameter on the Get-VM


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

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

I am running this:

 

$vmName = Get-VM

$copyVm = "$($vmName)_replica"

Get-VM -Name $vmName | Get-TagAssignment | ForEach-Object -Process { New-TagAssignment -Entity $copyVm -Tag $_.Tag }

 

And when I get to the $copyVm = "$($vmName)_replica" part it combines all the VMs together in one line.  The next part then looks for a VM named everything.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I meant like this

Get-VM | Get-TagAssignment |
ForEach-Object -Process {
  New-TagAssignment -Entity "$($_.Entity.Name)_replica" -Tag $_.Tag
}


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

0 Kudos