I want to get a listing of VMs where the name contains a particular string. For example purposes, the string is: red.ball.ad
Once I get this listing, I want assign a tag (OVA) to them.
Thanks in advance for your help.
In its simplest form that could look something like this
Get-VM -Name "*red.ball.ad*" |
New-TagAssignment -Tag 'OVA' -Confirm:$false
But there are a couple of things that can be improved.
- the Name can be tested with a Where-clause and a -match operator, which allows a RefEX
- you can use Try-Catch to cope with a non-existing Tag (and/or Tag Category)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
In its simplest form that could look something like this
Get-VM -Name "*red.ball.ad*" |
New-TagAssignment -Tag 'OVA' -Confirm:$false
But there are a couple of things that can be improved.
- the Name can be tested with a Where-clause and a -match operator, which allows a RefEX
- you can use Try-Catch to cope with a non-existing Tag (and/or Tag Category)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD. The syntax works perfectly as you've written it, as none of the vms containing the string have been previously tagged. Your solution was far too obvious and I was making it harder than it needed to be.