title: PathTooLong error with Get-ChildItem in PowerShell v3, but not v2
body: <p>On a <a href="http://en.wikipedia.org/wiki/Windows_Server_2008" rel="nofollow">Windows Server 2008</a> R2 VM, I upgraded PowerShell to v3 hoping to take advantage of the <a href="http://technet.microsoft.com/en-us/library/hh849800.aspx" rel="nofollow">Get-ChildItem</a> (gci) performance improvement. This line ran without error in v2:</p>
  
  <pre><code>$search = gci $dir -recurse -exclude "*.mdf" | where {$_.length -gt 100mb}
  </code></pre>
  
  <p>After upgrading to v3, why does the same line give this error? The <code>$dir</code> value is unchanged.</p>
  
  <blockquote>
    <p>gci : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less
    than 248 characters.
    At line:1 char:11
    + $search = gci $dir -recurse -exclude "*.mdf" | where {$_.length -gt 100mb}
    +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ReadError: (\server.domain...DETAILS 1.0.prt:String) [Get-ChildItem], PathTooLongException
        + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand</p>
  </blockquote>
  
  <p>There is no change after applying Windows Updates and rebooting. I took a snapshot of the VM before upgrading PowerShell, so I have the luxury of toggling back and forth easily.</p>
  
  <p><code>$errorActionPreference</code> is <code>Continue</code> in both v2 and v3.</p>
  
  <p><code>$search.count</code> is 8 in both v2 and v3, so I'm not super concerned about missing stuff, but would like to understand the change in behavior.</p>
  
  <p>I tried addding <code>-force</code> in v2, saw similar PathTooLong errors, and <code>.count</code> is 10. After adding <code>-force</code> in v3, <code>.count</code> was 9. I then reverted to v2 and again found 10 files with <code>-force</code>. It's nevertheless possible that changing data under <code>$dir</code> could explain the <code>.count</code> difference, but in our environment, changing data couldn't realistically explain the consistent presence of PathTooLong errors in v3, but not v2. Now that my curiosity has gotten the better of me, I'm hoping someone has a lead on this mystery and will spare me the error handling which, I admit, might offer more clues.</p>
  
  <p>FWIW, the <a href="http://technet.microsoft.com/en-us/library/hh849800.aspx" rel="nofollow">usage documentation on TechNet</a> says it applies to both v2 and v3. The <code>-Force</code> parameter's default value is False.</p>
  
  <p><a href="http://connect.microsoft.com/PowerShell/feedback/details/276235/path-length-limitations" rel="nofollow">Some background</a> on PowerShell and <code>MAX_PATH</code> from the v1 days.</p>
  
  <p>On a <a href="http://en.wikipedia.org/wiki/Windows_Server_2008" rel="nofollow">Windows Server 2008</a> R2 VM, I upgraded PowerShell to v3 hoping to take advantage of the <a href="http://technet.microsoft.com/en-us/library/hh849800.aspx" rel="nofollow">Get-ChildItem</a> (gci) performance improvement. This line ran without error in v2:</p>
  
  <pre><code>$search = gci $dir -recurse -exclude "*.mdf" | where {$_.length -gt 100mb}
  </code></pre>
  
  <p>After upgrading to v3, why does the same line give this error? The <code>$dir</code> value is unchanged.</p>
  
  <blockquote>
    <p>gci : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less
    than 248 characters.
    At line:1 char:11
    + $search = gci $dir -recurse -exclude "*.mdf" | where {$_.length -gt 100mb}
    +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ReadError: (\server.domain...DETAILS 1.0.prt:String) [Get-ChildItem], PathTooLongException
        + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand</p>
  </blockquote>
  
  <p>There is no change after applying Windows Updates and rebooting. I took a snapshot of the VM before upgrading PowerShell, so I have the luxury of toggling back and forth easily.</p>
  
  <p><code>$errorActionPreference</code> is <code>Continue</code> in both v2 and v3.</p>
  
  <p><code>$search.count</code> is 8 in both v2 and v3, so I'm not super concerned about missing stuff, but would like to understand the change in behavior.</p>
  
  <p>I tried addding <code>-force</code> in v2, saw similar PathTooLong errors, and <code>.count</code> is 10. After adding <code>-force</code> in v3, <code>.count</code> was 9. I then reverted to v2 and again found 10 files with <code>-force</code>. It's nevertheless possible that changing data under <code>$dir</code> could explain the <code>.count</code> difference, but in our environment, changing data couldn't realistically explain the consistent presence of PathTooLong errors in v3, but not v2. Now that my curiosity has gotten the better of me, I'm hoping someone has a lead on this mystery and will spare me the error handling which, I admit, might offer more clues.</p>
  
  <p>FWIW, the <a href="http://technet.microsoft.com/en-us/library/hh849800.aspx" rel="nofollow">usage documentation on TechNet</a> says it applies to both v2 and v3. The <code>-Force</code> parameter's default value is False.</p>
  
  <p><a href="http://connect.microsoft.com/PowerShell/feedback/details/276235/path-length-limitations" rel="nofollow">Some background</a> on PowerShell and <code>MAX_PATH</code> from the v1 days.</p>