title: How to edit a PowerShell array item returned by a search?
body: <p>I am trying to change a value of a specific item in a hash table. I can do this by iterating through the entire object, testing every single key for a specific value, then changing it if the condition is met like so:</p>
  
  <pre><code>for ($i=0; $i -le $haystack.length-1; $i++)
      {
          if ($haystack[$i].name -eq "needle")
              {
              $haystack[$i].currentstatus = "found"
              }
      }
  </code></pre>
  
  <p>The above code works but it seems like there has to be a more efficient way to accomplish the task especially when the haystack is large and there is only one needle.</p>
  
  <p>I tried to use where-object and can find the record I'm looking for:</p>
  
  <pre><code>$haystack | where-object {$_.name -eq "needle"}
  </code></pre>
  
  <p>This seems much better than doing a brute force search but I do not know how to get at that record now. If I had the index in the array then I can easily use that to edit the value I want so is there a way to get the array index? How is this usually done? Thanks.</p>