title: Filter Get-ADComputer where "Name -notlike" in Powershell
body: <p>My goal is to get a list of AD computer objects not following naming conventions with the whenCreated property. I am trying to export out a HTML file using the following PowerShell function: </p>
  
  <pre><code>function get_bad_names
  {
  $result = Get-ADComputer -searchbase $OU
  -Filter {Name -notlike 'name1' -and 
           Name -notlike 'name2' -and
           Name -notlike 'name3'} 
  -Properties whenCreated | sort whenCreated
  
  $result | ConvertTo-Html | Out-File $dir\badnames.html
  }
  
  get_bad_names
  </code></pre>
  
  <p>Is there a more elegant way of structuring the Name filter lines? We have over 40 lines of different "names." In other words, over 40 lines in my script say <code>Name -notlike 'name#' -and</code></p>
  
  <p>Ideally I'd like for the code to read from a text file and export out the same results. </p>
  
  <p>FYI: this function works but it is not ideally written. Any suggestions would be appreciated. </p>