Looking back at the "hard way" examples that Carter provided earlier, I see a line like this:
$nvc = new-object System.Collections.Specialized.NameValueCollection
Now, I don't really know what these objects do that is so special, never used them before, but...Once I saw in the code how it is used, I'm left wondering why can't I use a native powershell hashtable? e.g.
$filter = @{ Name = "MyVirtualMachine" }
to be followed by "find-entityview -viewtype VirtualMachine -filter $filter" for example.
This seems like a really logical way to go, but again I admit I don't know crap about NVCs so maybe there's a reason something like this can't be done.
Doesn't work.
83# $filter = @{ 'guest.guestState' = 'running'; 'guest.toolsStatus' = 'toolsOk' } 84# $filter Name Value ---- ----- guest.toolsStatus toolsOk guest.guestState running 85# $vms = Find-EntityViews -ViewType VirtualMachine -Filter $filter Find-EntityViews : Cannot bind parameter 'Filter'. Cannot convert "System.Collections.Hashtable" to "System.Collections.Specia lized.NameValueCollection". At line:1 char:57 + $vms = Find-EntityViews -ViewType VirtualMachine -Filter <<<< $filter
Good news. VMware decided to create a new constructor for the underlying method so that it'll take hashtables.