VMware Cloud Community
Mili_Durasovic
Contributor
Contributor
Jump to solution

get-tag by category AND VM

Hello,

is it possible to get a tag that has been assigned to a specific VM?

Backround is, that I want to configure 4 Uninterruptible Power supplies in 4 different rooms to run a script when the power goes down. Basically if the power in one building goes down it should run a script on the esx-server to move all the running VM´s on to the esx-server to a room in the other building.

I thought that it would be practical to make a tag on each VM with the information where to it should be moved when the power goes out. That way I can dynamically say VM001 is going to be moved on one esxserver and VM002 on another, without changing the script itself too much.

like for example:

VM001 (a vm on ESXSERVER1)

Category: BackupESXSERVER

TAG: ESXSERVER2 (so if the power goes out for ESXSERVER1 and it runs on the UPS, it should be moved to ESXSERVER2)

But how to I read which tag has been assigned to the VM from the category "BackupESXSERVER"?

get-tag -category BackupESXSERVER -VM ????

I can´t find a solution in the documentation. Is there a way?

vSphere 5.5 Documentation Center

Tags (3)
Reply
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You have to use the Get-TagAssignment cmdlet to retrieve the tag assignment. For example:

Get-VM -Name VM001 | Get-TagAssignment -Category BackupESXSERVER | Select-Object -ExpandProperty Tag | Select-Object -ExpandProperty Name

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

Reply
0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You have to use the Get-TagAssignment cmdlet to retrieve the tag assignment. For example:

Get-VM -Name VM001 | Get-TagAssignment -Category BackupESXSERVER | Select-Object -ExpandProperty Tag | Select-Object -ExpandProperty Name

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
Mili_Durasovic
Contributor
Contributor
Jump to solution

Thanks! This should do it.

I´m going to test it today.

Reply
0 Kudos