title: Powershell Conditional filter without regex
body: <p>Im trying to filter ADComputer by  Name.</p>
  <p>Our naming  convention  is  a  follows <code>&lt;CuntryCode&gt;-&lt;Location&gt;-&lt;DeviceType And Number&gt;</code> we have diferent  locations  in both  USA and  MX,  we also have serval  type of  devices</p>
  <p>Example:<br />
  <code>&lt;Device Type&gt;</code>
  <code>Servers  = S</code>
  <code>Desktops = D</code>
  <code>Laptops = L</code>
  <code>Tablet = T</code>
  <code>Routers = R</code>
  <code>Switches = U</code></p>
  <p>example of  actual naming:</p>
  <p><strong>MX-BCN-D002  or  US-TAM-L001</strong></p>
  <p>Im creating  a  Script  that  will  look  at a remote PC  file  system, and check  if  user has  a local  .PST file.  I  only  want   devices  that  are   Type:   Desktops  and Laptops,  but  cant seem  to  create a condition to  filter all other  devce  type</p>
  <p>Partial  Script:</p>
  <pre><code>$Enabled_PC_list =@()
  $Enabled_Online_PC_List =@()
  # $Enabled_Offline_PC_list =@()
  $data = @()
  
  $PCs = Get-ADComputer -filter &quot;Enabled -eq '$true'&quot; -SearchBase &quot;DC=some,DC=domain&quot; -properties name | Select-Object -ExpandProperty name
  
  $Enabled_PC_list += $PCs
  
  foreach($device in $Enabled_PC_list){
  
      Write-Output &quot;&gt;&gt;&gt; testing  Device: $device &lt;&lt;&lt;&quot;
      if ($device -like &quot;*-*-D*&quot; -or  $device -like &quot;*-*-L*&quot; ) {
          if(Test-Connection -TargetName $device -Count 1 -Quiet){
              $Enabled_Online_PC_List += $device
          }
  
      }else{
          Write-Output &quot;Device  $device not valid &quot;
      }
  
  
      }
  } 
  </code></pre>
  <p>So  with this  line  <code>if ($device -like &quot;*-*-D*&quot; -or  $device.name -like &quot;*-*-L*&quot; )</code> i  was hoping to filter out  all devices  that matched   what  im looking  for and proceed  to do  a   Test-Connection  on those  devices .</p>
  <p>Do  i need  to use  regex  on this ?<br />
  How  can i  use  regex in powershell?
  Is there  a  better  way ?</p>