Automation

 View Only
  • 1.  Selecting Array objects from a hash table

    Posted Mar 04, 2014 05:16 PM

    Suppose I have a hash table with a list of virtual machine names.  I also have an array variable containing virtual machine objects and all of their properties.  I want to cycle through the array variable and remove all of the virtual machine names that do not exist in the hash table.  How would I accomplish this?

    Thanks



  • 2.  RE: Selecting Array objects from a hash table
    Best Answer

    Posted Mar 04, 2014 05:55 PM

    If your array is called $inArray and your hash table is called $hashTab, you could do something like this

    $outArray = $inArray | %{

        if($hashTab.ContainsKey($_.VMName)){

            $_

        }

    }

    The selected objects will in array $outArray.



  • 3.  RE: Selecting Array objects from a hash table

    Posted Mar 10, 2014 11:05 PM

    OK great thanks again