VMware Cloud Community
vCJ
Contributor
Contributor
Jump to solution

Syncronize "tags" between vcenter servers

Maybe someone already have a solution for this, so I will ask here before I pull all my hair out.

In one of our vcenter we started using tags a while back. Looks like that is the way we want to go, so now the challenge is how to "sync" tags between all our vcenter servers.

Hopefully some of you already have a way of doing this, or some idea on where to start.

I guess we could export using csv and import to an other vcenter? Or is there a better way?

All suggestions are very welcome at this stage..

Best Regards

Jorgen S

If the only tool you have is a hammer, you tend to see every problem as a nail...
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could use a CSV file to export/import categories and tags.

Something like this.

Note that depending on the number of connections you have open, you would need to use the Server parameter to indicate where to export/import.

1) Export

&{foreach($tCat in Get-TagCategory){

    $tags = Get-Tag -Category $tCat

    if($tags){

        $tags | Select @{N='Category';E={$tCat.Name}},@{N='cDescription';E={$tCat.Description}},@{N='Cardinality';E={$tCat.Cardinality}},Name,Description

    }

    else{

        $tCat | Select @{N='Category';E={$tCat.Name}},@{N='cDescription';E={$tCat.Description}},@{N='Cardinality';E={$tCat.Cardinality}},@{N='Name';E={''}},@{N='Description';E={''}}

    }

}} | Export-Csv C:\tag.csv -NoTypeInformation -UseCulture

2) Import

foreach($tag in Import-Csv c:\tag.csv -UseCulture){

    Try{

        Get-TagCategory -Name $tag.Category -ErrorAction Stop

    }

    Catch{

        New-TagCategory -Name $tag.Category -Description $tag.cDescription -Cardinality $tag.Cardinality -Confirm:$false

    }

    if($tag.Name){

        Try{

            Get-Tag -Category $tag.Category -Name $tag.Name -ErrorAction Stop

        }

        Catch{

            New-Tag -Name $tag.Name -Category $tag.Category -Description $tag.Description -Confirm:$false

        }

    }

}


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

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

What exactly do you want to sync ?

The tag categories, the tag assignments....?

If it's tag assignments, how does that work with entities. Are the same entities present ion both vCenters ?


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

Reply
0 Kudos
vCJ
Contributor
Contributor
Jump to solution

Hi LucD Smiley Happy

I basically just wanna copy/paste all the categories and tags, not the assignments

That way we have the same tag "library" in all vcenters.

I just dont want to manually insert all the categories and tags in all my vcenters.

Create in "master" vcenter --> copy to all other vcenter servers.

- No, vm relations that will be set in the individual vcenter when new vm's get deployed.

I just need the tags and the tag categories to be there when someone deploy a new vm and then they can assign the right tag for their vm.

If the only tool you have is a hammer, you tend to see every problem as a nail...
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could use a CSV file to export/import categories and tags.

Something like this.

Note that depending on the number of connections you have open, you would need to use the Server parameter to indicate where to export/import.

1) Export

&{foreach($tCat in Get-TagCategory){

    $tags = Get-Tag -Category $tCat

    if($tags){

        $tags | Select @{N='Category';E={$tCat.Name}},@{N='cDescription';E={$tCat.Description}},@{N='Cardinality';E={$tCat.Cardinality}},Name,Description

    }

    else{

        $tCat | Select @{N='Category';E={$tCat.Name}},@{N='cDescription';E={$tCat.Description}},@{N='Cardinality';E={$tCat.Cardinality}},@{N='Name';E={''}},@{N='Description';E={''}}

    }

}} | Export-Csv C:\tag.csv -NoTypeInformation -UseCulture

2) Import

foreach($tag in Import-Csv c:\tag.csv -UseCulture){

    Try{

        Get-TagCategory -Name $tag.Category -ErrorAction Stop

    }

    Catch{

        New-TagCategory -Name $tag.Category -Description $tag.cDescription -Cardinality $tag.Cardinality -Confirm:$false

    }

    if($tag.Name){

        Try{

            Get-Tag -Category $tag.Category -Name $tag.Name -ErrorAction Stop

        }

        Catch{

            New-Tag -Name $tag.Name -Category $tag.Category -Description $tag.Description -Confirm:$false

        }

    }

}


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

Reply
0 Kudos
vCJ
Contributor
Contributor
Jump to solution

This was just perfect LucD, thank you so much. Smiley Happy:smileyplus:Smiley Happy

If the only tool you have is a hammer, you tend to see every problem as a nail...
Reply
0 Kudos
ifany
VMware Employee
VMware Employee
Jump to solution

This works on 6.5 just ran it today.

Reply
0 Kudos