title: ForEach loop in PowerShell failing after first iteration
body: <p>I have an array, $Conventional, which I need to loop through and click each time so that I can save the PDFs which are made available after the click(). </p>
  
  <pre><code>$Conventional = @()
  $Conventional = $ie.Document.getElementsByTagName("td") | ? {($_.getAttributeNode('class').Value -match 'NodeDocument') -and ($_.innerText -notmatch 'Library Home')}
  </code></pre>
  
  <p>This fills $Conventional with four <code>td</code> elements which I need to loop through and click() each time. The following is my ForEach loop which works fine on the first iteration, however it then fails and returns <code>System.ComObject</code> each time after that. </p>
  
  <pre><code>ForEach ($i in $Conventional){
  
      $text = $i.innerText    
  
      $i.click()               
      while ($ie.Busy -eq $true){Start-Sleep -Seconds 2}
  
      $PDF = $ie.Document.getElementById("OurLibrary_LibTocUC_LandingPanel_libdocview1_DocViewDocMD1_hlViewDocument")
  
      $currentURL = $PDF.href
      $fileName = $baseFileName + "_" + $cleanText
  
      Invoke-WebRequest -Uri $currentURL -OutFile $NewPath\$fileName.pdf -WebSession $freedom
  } 
  </code></pre>
  
  <p>Here is a screenshot of the array I am capturing. In order to retrieve the PDFs, each one needs to be clicked. 
  <a href="https://i.stack.imgur.com/tSRXR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tSRXR.png" alt="screenshot of $Conventional array"></a></p>
  
  <p>Any help would really be appreciated. Thanks everyone</p>