Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 219257

Re: get-view

$
0
0

Hello-

 

Here you got around the "supplying a VirtualMachineImpl as the value to the Name key in the Get-View Filter" by getting the String value of $vmname.  Again, $vmname in your example is a VirtualMachineImpl object.  So, if you look at the contents of that variable, you should see a full virtual machine object, like:

Name  PowerState Num CPUs MemoryGB
----  ---------- -------- --------
myVM0 PoweredOff 1        1.000

 

But, by adding quotes around the variable, you are creating a string, and the .ToString() method of the $vmname variable is invoked, which results in just the String value that is the name of the VM.  That set of quotes around $vmname in the Filter hashtable is the difference between this post and your original post, and the reason why both of your examples in this "what is the difference here" post work.

 

As for what is the difference:

  • the first example is getting VirtualMachine objects whose name matches the given value in the Filter
  • the second example uses the ID of the VirtualMachineImpl object (which corresponds to the MoRef of the managed object) to get the VirtualMachine object

 

Another difference:  the first example might get more than one VirtualMachine object, whereas the second example should get exactly one VirtualMachine object (assuming that you are connected to only one vCenter, and that a VirtualMachine with that ID still exists).

 

The reason that the first example might return multiple VirtualMachine objects is that the filter is using regular expression matching on the name pattern that you supplied as a value to the "Name" key.  So, the regular expression of "myVM0" matches, of course, "myVM0", but also matches "myVM01", "myVM0_old", "do_not_use_this_vm_myVM0", and so on.

 

Make sense?


Viewing all articles
Browse latest Browse all 219257

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>