title: PowerShell using a Foreach, if Statement and an array to import and export CSV
body: <p>I'm trying to have PowerShell go through a CSV and remove anything that is in the “$skip” array then save the file. If I replace the $skip variable with the actual word on the IF line it will work, however when I use the variable nothing will be removed.</p>
  <pre><code>$file = &quot;c:\temp\employee.csv&quot;
  $skip = &quot;ax1&quot;,&quot;ax2&quot;,&quot;testdummy1&quot;
  
  Get-ADUser -Filter * -SearchBase $ou -Properties EmployeeID, Department,mailNickname |
  Select-Object Name,mailNickname,UserPrincipalName,DistinguishedName,EmployeeID,Department `
  | Export-Csv -Path $file
  
  $list = foreach($line in Get-Content $file)
  {
      IF($line -like $skip)
      {}
      Else 
      {$line}
  }
  $list| Set-Content $fileout -Force
  </code></pre>