0

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

1 Answer 1

1

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}
Sign up to request clarification or add additional context in comments.

1 Comment

How would I do want I want though?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.