title: How to find if Powershell Array Contains Object of Another Array
body: <p>I have to arrays in Powershell. Each Array contains an array of objects. These objects have two properties:</p>
  
  <p><strong>Name</strong>: String<br>
  <strong>Id</strong>: GUID</p>
  
  <p>The first Array has 4413 objects in it and the second has 4405. The counts are irrelevant, but I only mention them to note that the contents of Array1 and Array2 are different.</p>
  
  <p>Here is my current code (pseudo):</p>
  
  <pre><code>#Fill Array1
  $Array1 = Fill-Array1
  
  #Fill Array2
  $Array2 = Fill-Array2
  
  #Loop through the arrays and write out the names of all items in Array2 that are different than Array1
  ForEach($Val in $Array2)
  {
      $Name = $Val.Name
  
      If($Array1 -notcontains $Val) //this does not work
      {
          Write-Host $Name
      }
  }
  </code></pre>
  
  <p>What is the correct way to check for the existence of the object in Array1? Is my only option to do a nested loop?</p>
  
  <p><strong>Update, using the answer from <a href="https://stackoverflow.com/users/7890164/manu-p">Manu P</a> below, the following is how I implemented the solution:</strong></p>
  
  <pre><code>#Fill Array1
      $Array1 = Fill-Array1
  
      #Fill Array2
      $Array2 = Fill-Array2
  
      #Compare the arrays
      $ComparedResults = Compare-Object -ReferenceObject $Array1 -DifferenceObject $Array2 #I left out the -IncludeEqual param because I don't care about those results
  
      ForEach($Result in $ComparedResults)
      {
          If($Result.SideIndicator -eq "=&gt;") #the value in Array2 is different than Array1
          {
              $Val = $Result.InputObject
  
              Write-Host $Val.Name            
          }        
      }
  </code></pre>