PowerCLI for 'Not' VMs in a folder

I am trying to retrieve a list of virtual computer with the exception of a select few names I want to accomplish this in DOES not receive the names in a certain folder.

I tried this example:

Get - VM | where {$_.} Name - don't (Get-Data-Center "someDataCenter" |) Get-file "SomeFolder" | Get - VM)}

I realize that I could take the long way around and record the names of the virtual machines in a txt and then get back them with something like:

Get - VM | where {$_.} Name - only (type c:\folder\file.txt)}

But I want to know how logically the action the other direction.

In addition, and this excited me was really until I completely failed him... I tried this:

$vms = get - VM

{Foreach ($vm to $vms)
{Switch ($VM)}
(Get-Datacenter "MyCenter" |) Get-file test. Get - VM) {}
default {$exclude += $_.} Name}
}
}
I tried to accomplish VMs not getting NOT another way, and I didn't want to wait to 'write' list the names of virtual machine, so I thought that I could save by default as a variable called $exclude and continue to add each VM name on it.
What happened was that I have this long with each VM set name variable... so if I had 2 VMs named 'Test' and 'Test1', the variable $exclude would show this:
PS C:\ > $exclude
TestTest1
Each individual letter would be a table element, $exclude [0] would be the letter "T" Test and not the name VM 'Test '.  Thanks for any help, and I hope that I have explained clearly.

Maybe something like that? :

#Omits parent folder names that match nameoffolder1 or foldername1
Get-VM | where-object {$_.Folder -notmatch "nameoffolder1|foldername1"}
#OR this which omits any vm w/ a parent folder matching the string nameoffolder
Get-VM | where-object {$_.Folder -notmatch "nameoffolder"}

Post edited by: Zsoldier

Tags: VMware

Similar Questions

Maybe you are looking for