Reputation: 19
I am trying to run a VMWare powershell script where I grab all the VM's besides the ones with the tag "NO_SNAPSHOT"
To get the list of VM's I run this to remove the ones with the tag "NO_SNAPSHOT"
$VMs = Get-VM| Where-Object { $_.tag -notlike '*NO_SNAPSHOT*'}
However it doesn't work, it still lists all the VM's
Upvotes: 0
Views: 4091
Reputation: 1983
Objects returned by Get-VM
do not have a property called 'Tag'. Check out Get-TagAssignment.
edit - so you could do
$TAs = Get-TagAssignment | where {$_.tag.name -like "*no_snapshot*"}
$VMs = get-vm | where { $TAs.entity.name -notcontains $_.name }
Or if you have PowerCLI v5.8r1 you could do
$noSnap = get-vm -tag *no_snapshot*
$vms = get-vm | where {$noSnap.name -notcontains $_.name}
Upvotes: 1