title: Get-ChildItem -Recurse throws System.OutOfMemoryException
body: <p>I run this function on a big directory:</p>
  
  <p><em>Definition</em></p>
  
  <pre><code># (searches for all ips within files in the current directory recursively)
  
  function searchips
  {
      param(
          [Parameter(Mandatory=$false)][string]$dir = $(pwd)
      )
  
      ls -Recurse -Force `
      | Select-String -Pattern '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' -AllMatches `
      | ? { 
          $matches = ($_.Matches | Select-Object -Unique)
          return $matches.Count -gt 1 -or $matches[0].Value -ne '127.0.0.1' 
      } `
      | select Path,Matches,FileName,LineNumber,Line `
      | Format-Table -AutoSize `
      | Out-String -Width 4096
  }
  </code></pre>
  
  <p><em>Call</em></p>
  
  <pre><code>PS C:\path\to\huge&gt; searchips hugeDirectory &gt;&gt; outfile.txt
  </code></pre>
  
  <p>But I get this error every single time:</p>
  
  <pre>out-lineoutput : Exception of type 'System.OutOfMemoryException' was thrown.
  At C:\Users\myUserName\Documents\WindowsPowerShell\profile.ps1:73 char:2
  +     ls -Recurse `
  +     ~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [out-lineoutput], OutOfMemoryException
      + FullyQualifiedErrorId : System.OutOfMemoryException,Microsoft.PowerShell.Commands.OutLineOutputCommand</pre>
  
  <p>Currently my PS memory settings look like this:</p>
  
  <pre>   WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Shell
  
  Name                      Value         Type
  ----                      -----         ----
  AllowRemoteShellAccess    true          System.String
  IdleTimeout               7200000       System.String
  MaxConcurrentUsers        10            System.String
  MaxShellRunTime           2147483647    System.String
  MaxProcessesPerShell      25            System.String
  MaxMemoryPerShellMB       9000000       System.String
  MaxShellsPerUser          30            System.String</pre>
  
  <p>Any ideas?</p>