A Sysadmin

  • Archive
  • RSS
  • Ask me almost anything

Powershell: Path length limitation

It seems that with Powershell and all things .net and most things in windows you are limited to a full path length of 260 characters and the longest directory can only be 248 characters long.

This is something that Microsoft is not planning to change and wants everyone to just use shorter paths. This is the right solution in most cases but annoying since they themselves do not fallow this when it comes to the User Profile, where all browsers store their cache files there using more than 260 characters full paths.

There is one work around in powershell and that is to execute a normal DIR command. The limitation of this is you only get an array of full paths but cant do anything with it in Powershell.

If you execute this command in powershell you will get a few errors regarding path length.

Get-ChildItem C:\Users -recourse

The Dir version is longer since you have to strip the extra information from the results.

$folders = cmd /c dir C:\Users /s /-c /a:h /a:d
$folders = $folders -match “Directory”
$folders = $folders | %{$_.Replace(” Directory of “,”“)}

First line runs the DIR command, second line filters just to directories and the third one removes the descriptive text. In the end you have an array with all the paths, regardless of length.

    • #powershell
  • 1 year ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Recent comments

Blog comments powered by Disqus
← Previous • Next →

Portrait/Logo

Pages

  • About
  • Powershell Scripts
  • RSS
  • Random
  • Archive
  • Ask me almost anything
  • Mobile
Effector Theme by Pixel Union