PowerShell script to identify documents with long path names

I wrote this PowerShell script to identify all documents in a site that exceed 256 characters in length.  See http://technet.microsoft.com/en-gb/library/ff919564(v=office.14).aspx for more information.

Feel free to copy the code and use the script as you see fit (at your own risk of course, I can not and will not take responsibility for any undesired outcome).

Param([String] $Site = $(Throw 'Error, no site URL specified.'))

<#
---------------------------------------------------------------------
PowerShell script to report on all files and folders within a site
that exceed 256 characters.  For more information, see the link
below.

File    : Get-LongPaths.PS1
Author  : David Webb
Date    : 19/06/2014
Version : 1.0

Revision history:
-----------------
1.0 Initial version

Usage:
------ 
Run Get-LongPaths.PS1 <Site URL>
Example: Get-LongPaths.PS1 http://intranet/hr

---------------------------------------------------------------------
#>

# -----------------------
# Add required snap-in(s)
# -----------------------

Add-PSSnapin Microsoft.SharePoint.PowerShell -ea 0

# -----------------------
# Define global variables
# -----------------------

$Date = Get-Date -Format yyyy-MM-dd_h-mm
$Logging = "True"
$LogFile = "C:\Get-LongPaths $Date.log"

If ($Site.EndsWith("/"))
{ 
   $Site = $Site.Substring(0,$Site.Length-1)
}

# ------------------------------------------------------------------
# Function to report on folders that exceed 256 characters in length
# ------------------------------------------------------------------

Function Get-LongPaths([String]$Site)
{
   $Web = Get-SPWeb -Identity $Site

   ForEach ($List in $Web.Lists)
   {
      If ($List.BaseType -Eq "DocumentLibrary")
      {
         ForEach ($Item in $List.Items)
         {
            $FullURL = $Site + "/" + $Item.Url
            If ($FullURL.length -gt "256")
            {
               Write-Host $FullURL "-" $FullURL.Length
               If ($Logging -eq $True)
               {
                  $FullURL | Out-File -Append $LogFile
               }
            }
         }
      }
   }
}

Get-LongPaths $Site

 

[BlogBookmark] [Blogsvine] [del.icio.us] [Digg] [Facebook] [Furl] [Google] [LinkedIn] [MySpace] [Reddit] [Slashdot] [StumbleUpon] [Twitter] [Windows Live] [Yahoo!] [Email]