title: Get-ChildItem Where-Object -notlike $array - Is there a way to do this?
body: <p>I have written a script that will recurse a specified folder and do some analysis on the files within it. I need to exclude specified sub-folders in the analysis. This list of exclusions changes dependent on the base folder being analysed. I have the script working using a long pattern like this:</p>
  
  <pre><code>Get-ChildItem -File -Recurse $source_folder | 
  Where-Object {
      $_.FullName -notlike "*\folder_name0\*" -and 
      $_.FullName -notlike "*\folder_name1\*" -and 
      $_.FullName -notlike "*\folder_name2\*" -and 
      $_.FullName -notlike "*\folder_name3\*" -and 
      $_.FullName -notlike "*\folder_name4\*"
  }
  </code></pre>
  
  <p>but this is not very reusable. I would like to be able to store exception lists in .CSVs and call the exception list I need based on the folder set I am analyzing. What I would like to do is something like:</p>
  
  <pre><code>$exception_list = Import-CSV .\exception_list
  Get-ChildItem -File -Recurse $source_folder | 
  Where-Object {$_.FullName -notlike $exception_list}
  </code></pre>
  
  <p>but this does not work. I suspect because I can't specify and 'and' or an 'or' between the elements in the array. I did briefly consider trying to create the whole argument on the fly using a <code>foreach($exception in $exception_list){$argument += "$_.FullName -notlike $exception -and"}</code>, but that got silly and complex pretty quickly since you still have to remove the last 'and'.</p>
  
  <p>Is there an efficient way to do this?</p>