I have a report that uses two arrays and a hashtable.
1. $report = An array containing a group of VMs and custom properties for those VMs. The virtual machine names are in a property called VMName
2. $removedvms = An array containing a list of virtual machine names. The virtual machine names are also in a property called VMName
3. $vmhash = A hash table
For every virtual machine object that is present in the $report array and also has its name listed in the $removedvms array, I would like to remove the object from the $report array. Using the code below, the hash table now has only the names of the VMs that are in $report but are NOT in $removedvms.
How do I remove the objects from $report that are NOT in $vmhash?
$vmhash=@{}
$report | %{$vmhash.Add($_.VMName,$_)}
$removedvms | %{
if($vmhash.ContainsKey($_.Name)){
$vmhash.Remove($_.Name)
}
}