Pre-check for long file path names using PowerShell script

Modified on Thu, 1 Sep, 2016 at 2:47 PM

 The attached script can be run from PowerShell to produce a report on all files within a directory (and all sub-folders).

This script iterates through all files and directories in a given path and reports the full path length (in characters). The resulting data is output to the console and saved into a TXT file (in CSV format)


EXAMPLE
 

 .\Get-PathLength.ps1 -pathToScan "C:\Users\MyUserName\SharePoint\FolderName\" -outputFilePath "C:\o365\PathLengthsOutput.txt"

 

 

PARAMETER pathToScan

The absolute path on the local computer, encapsulated in quote marks

PARAMETER outputFilePath
The absolute path to the TXT report file on the local computer. The text is formatted as CSV with column headings "FileNum,PathLength,FullPath".  Sorting the report in a spreadsheet (PathLength, DESC) will reveal any paths over the 250 max limit.  Sorting by FileNum returns the list to the actual folder path/structure on the PC

NOTES
If pre-scanning files on an existing server share, please note that the OneDrive/Sharepoint path may likely be much longer than the original.

  • Example on old server share: "D:\Company Shared\..." (Full path length = 18 + sub-path length)
  • Example on SharePoint:"C:\Users\MyUserName\SharePoint\Name of Business - Documents\..." (Full path length = 60 + sub-path length)
  • Example on OneDrive:"C:\Users\MyUserName\OneDrive - Name of Business\..." (Full path length = 48 + sub-path length)

Based upon the above examples:
  If scanning a local share a path length of 220 may appear well within the 250 character limit...
  ...but on SharePoint the path may be 32 characters longer (50-18=32), making 252 and thus over the limit

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article