VMware Cloud Community
mjw4847
Contributor
Contributor
Jump to solution

Tag All VMs with Specific Text in Name

I'm in need of a script that will tag all of the VMs that we have with "_replica" in the name.  I am just getting familiar with PowerCLI and don't know enough to create the script but we have an immediate need for it so I'm hoping someone here can get me started.  I plan to schedule the script to run periodically (assuming this can be done) to ensure that all replica VMs are tagged properly so they are excluded from backup and replication jobs (we exclude them by tag in Veeam).

Thanks for the help.

Matt

1 Solution

Accepted Solutions
jpsider
Expert
Expert
Jump to solution

How about something like this?

$mytag = Get-Tag -Name "MyTag"

$vmlist = get-vm | Where-Object {$_.name -like '*_Replica*'}

foreach ($vm in $vmlist) {

  New-TagAssignment -Tag $mytag -Entity $vm

}

View solution in original post

2 Replies
jpsider
Expert
Expert
Jump to solution

How about something like this?

$mytag = Get-Tag -Name "MyTag"

$vmlist = get-vm | Where-Object {$_.name -like '*_Replica*'}

foreach ($vm in $vmlist) {

  New-TagAssignment -Tag $mytag -Entity $vm

}

mjw4847
Contributor
Contributor
Jump to solution

That did the trick!  Thank you very much.

0 Kudos