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.