title: Powershell - IO.Directory - Find file types in all subdirectories
body: <p>I ran across this code in another post that almost does what I need, but can't figure out how to modify it to look for specific file types, i.e. *.bak, <em>.txt, etc.  I'm using Powershell with [System.IO.DirectoryInfo] because, like others have stated, using Get-ChildItem is too slow across the network.  I thought it would just be something like $fileEntries = [IO.Directory]::GetFiles("C:\", "</em>.bak"), but it still returns every file in every directory. --PS/.NET newbie</p>
  
  <pre><code>try
  {
         $fileEntries = [IO.Directory]::GetFiles("C:\")
         [System.IO.DirectoryInfo]$directInf = New-Object IO.DirectoryInfo("C:\")
         $folders = $directInf.GetDirectories()
  }
  catch [Exception]
  {
         $_.Exception.Message
         $folders = @()
   }
  
  foreach($fileName in $fileEntries) 
  {
  
        #[Console]::WriteLine($fileName); 
  
  }
  
  Remove-Variable -ErrorAction SilentlyContinue -Name fileEntries 
  
  foreach($folder in $folders)
  {
      recurse("C:\" + $folder + "\")
  }
  </code></pre>