title: How to search array of objects contains an item in another array?
body: <p>I have two arrays.</p>
  
  <p>An array of objects containing Virtual Machine Information called <code>$vms</code> one of the attributes called <code>Name</code>. Here's the type:</p>
  
  <pre><code>PowerCLI &gt; $vms.GetType()
  
  IsPublic IsSerial Name                                     BaseType
  -------- -------- ----                                     --------
  True     True     Object[]                                 System.Array
  </code></pre>
  
  <p>I have another array imported from a CSV file called <code>$importVMs</code> where one of the fields is also called <code>Name</code>.</p>
  
  <p>I want to do some work if <code>$importVMs.Name</code> does not exist in <code>$vms</code> (i.e. it doesn't match any <code>$vms.Name</code>). I'm wondering if I can do this with pipelining, or do I have to iterate through both arrays?</p>
  
  <p>can I do something like <code>if (! $vms | ? {$_.Name -neq $importVms.Name) { # work }</code></p>
  
  <p>Can't seem to get it to work. Do I need to <code>foreach</code> the <code>$importVms</code> in that <code>if</code> condition?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>My complete script so far:</p>
  
  <pre><code>Connect-VIServer -Server vCenter -Protocol https -Force | out-null
  $importVms = Import-Csv vCenterVMs.csv
  $VMHost = "esxi"
  $currentVms = Get-VM
  Write-Host "Current registered VMs" -ForeGroundColor Cyan
  $currentVMs
  
  Write-Host "Saved VMs to import" -ForeGroundColor Yellow
  $importVms
  
  $registered = @()
  Write-Host "Importing VMs..." -ForeGroundColor White
  #$importVms | ?{$_.Name -notcontains $currentVms}
  
  foreach ($vm in $importVms) {
      if (! $currentVms.Name -contains $vm) {
          Write-Host "Importing $($vm.Name)"
          # put in a try block here
          $registeredVM = New-VM -VMFilePath $vm.VmPathName -VMHost $VMHost -Location $vm.Location
          $registeredList += $registeredVM.Name
      }
  }
  
  $registeredList
  Disconnect-VIServer -Server * -Confirm:$false
  </code></pre>
  
  <p>vCenterVMs.csv looks like</p>
  
  <pre><code>"Name","VmPathName","Location"
  "test","[RAID5] test/test.vmx","testfolder"
  </code></pre>