Hi!
We are trying to run this script to find URLs that are too long which prevent us from copying a site as a template. It’s not finding all URLs that are too long.
Seems as if it’s not going to the “sub-site” level…only current site:
Run following script with FindLongPaths.ps1 | Out-File -filepath C:\Output\LongFiles.csv
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
#Where to Download the files to.
$destination = “C:\DownloadedFiles”
#The site to extract from. Make sure there is no trailing slash.
$site = “http://spsite.com/IT/sites”
# Function: DownloadLongFiles
# Description: Downloads all documents with a URL > 260 characters
# Variables
# $folderUrl: The Document Library to Download
function DownloadLongFiles($folderUrl)
{
$folder = $web.GetFolder($folderUrl)
foreach ($file in $folder.Files)
{
$encodedURL = $file.url -replace ” “, “%20”
$FullURL = $site+’/’+$encodedURL
$URLWithLength = $FullURL+’#’+$FullURL.length
$Filename = $file.Name
$Downloadpath = $destination+’\’+$Filename
if ($FullURL.length -ge 260)
{
#Uncomment the line below to download the files.
#HTTPDownloadFile “$FullURL” “$Downloadpath”
Write-Host $FullURL
Write-Host $destination
Write-Host $URLWithLength
Write-Output $URLWithLength
}
}
}
# Function: DownloadSite
# Description: Calls DownloadLongFiles recursiveley to download all documents with long file names in a site.
# Variables
# $webUrl: The URL of the site to download all document libraries
function DownloadSite($webUrl)
{
$web = Get-SPWeb -Identity $webUrl
foreach($list in $web.Lists)
{
#if($list.BaseType -eq “DocumentLibrary”)
#{
DownloadLongFiles $list.RootFolder.Url
#Download files in folders
foreach ($folder in $list.Folders)
{
DownloadLongFiles $folder.Url
}
#}
}
}
# Function: HTTPDownloadFile
# Description: Downloads a file using webclient
# Variables
# $ServerFileLocation: Where the source file is located on the web
# $DownloadPath: The destination to download to
function HTTPDownloadFile($ServerFileLocation, $DownloadPath)
{
$webclient = New-Object System.Net.WebClient
$webClient.UseDefaultCredentials = $true
$webclient.DownloadFile($ServerFileLocation,$DownloadPath)
}
#Download Site Documents + Versions
DownloadSite “$site”
The best suggestion that I can provide for this type of issues is LongPathTool. Best of luck.
I would highly recommend you to use LongPathTool to deal with this type of issues. It worked for me.
To make file name shorter or problems regarding path too long, you can use LONGPATHTOOL. It works great.
You can try using LongPathTool. It will help with too long file names. Thank you.Â
We’re trying this as well:
if (!(Get-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue))
   { Add-PSSnapin microsoft.sharepoint.powershell }
$siteurl = “<SharePointSiteURL>”
$site = get-spsite $siteUrl
$output=@()
foreach ($web in $site.allwebs) {
   foreach ($list in $web.lists | where {$_.basetype -eq ‘DocumentLibrary’}) {
       foreach ($item in $list.items) {
           $encodedURL = $item.url -replace ” “, “%20”
           $fullURL = “$($web.Url)/$($encodedURL)”
           if ($fullURL.length -gt 260) {
               $output+= New-Object psobject -Property @{
                   ‘File Name’ = $item.name
                   ‘URL’ = $fullURL
                   ‘Lenght’ = $($fullURL.length)
               }
           }
       }
   }
}
$output | Export-Csv C:\report.csv -nti