2 Replies Latest reply on Jul 16, 2013 3:58 PM by np123

    specify vm name precisely with get-view -filter hash

    np123 Enthusiast

      I think I'm missing some quirk or convention with Powershell variables in a hash filter.

       

       

      My infrastructure includes these 3 VMs:
      UTIL
      otherUTIL
      anotherUTILserver

       

       

      I'm trying to use something like the following to return only the vm called UTIL. This returns all 3 VMs with UTIL in their name:

       

       

      $vm = "UTIL"

      Get-View -ViewType VirtualMachine -Filter @{"Name" = $vm} | select -expand name

       

      The get-view line below eliminates anotherUTILserver but still returns otherUTIL along with UTIL:

       

      Get-View -ViewType VirtualMachine -Filter @{"Name" = "$vm$"} | select -expand name

       

      With "$vm$" I'm following LucD's comment here: http://rvdnieuwendijk.com/2011/09/12/how-to-use-vmware-vsphere-powercli-to-find-the-mac-addresses-of-a-virtual-machine/#comment-22

       

      If necessary, I could resort to the slower-but-simpler get-vm, could add a foreach loop (my example is simplified), or could maybe filter on an additional property besides Name. But I'm hoping there's a similar trick that'll help the filter eliminate otherUTIL and return only UTIL, without adding complexity.