Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Powershell to find URL lengths greater than 260 characters

$
0
0

I need the Powershell to find URL lengths greater than 260 characters, I've tried using scripts from both the sites below.  1 doesn't output to a text file and the other tries to locate all files in the top level site and anything beneath it even when i specify a certain URL such as http://site1/subsite/siteb

https://sharepointnomad.wordpress.com/2010/07/31/locating-files-and-pages-with-urls-that-are-too-long-for-sharepoint/

http://www.nikcraik.ca/extract-sharepoint-files-with-long-names/

# Call this script as below
# powershell   C:\scripts\url.ps1  "http://spdev/sandbox"
# This script enumerates all files at the specified URL,
# and outputs full URL for each file,
# along with the length of the URL.

# define EnumPages function

function EnumPages
{
param ($URL, $objFolder)

 # enumerate files in the root folder

 foreach ($file in $objFolder.Files)
 {

 $result = "OK"
 $output = $URL + "/" + $objFolder.URL + "/" + $file.Name

#$output,  $URL ";" ,$objFolder.URL ,$file.Name |Out-File C:\Scripts\files.csv -append


# evaluate string length
 if ($output.length -ge 260) { $result = "TOO LONG" }

# write output

 # write-output $output, ";" , $output.length, ";" $result, ";"

$output ,$output.length,$result |Out-File C:\Scripts\files.csv -append

}
 # enumerate subfolders

 foreach ($subfolder in $objFolder.SubFolders)
 {

 EnumPages $URL $subfolder
 }

 }

 # begin script body
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null

 $siteURL = $args[0]

# create a new SPSite object

$site=new-object Microsoft.SharePoint.SPSite("http://sitename/site/project1")
$web = $site.OpenWeb()

 # enumerate files in the Rootweb

 foreach ($file in $site.Rootweb.Files)
 {

$result = "OK"

$output = $site.Rootweb.URL + "/" + $file.Name
#$output| Export-Csv c:/scripts/test.csv -NoTypeInformation

 if ($output.length -ge 260) { $result = "TOO LONG" }

  #write-host $output, ";", $output.length, ";" , $result

$output ,$output.length,$result |Out-File C:\longfilenames\files.csv -append


 }

 # enumerate folders in the Rootweb

 foreach ($folder in $site.Rootweb.Folders)
 {

 EnumPages $site.Rootweb.URL $folder

 }

 # enumerate subsites

 foreach ($web in $site.Allwebs)
 {

  # enumerate files in the root web

  foreach ($file in $web.Files)
  {

$result = "OK"

$output = $web.URL + "/" + $file.Name

 if ($output.length -ge 260) { $result = "TOO LONG" }

 #write-host $output, ";", $output.length, ";" , $result

$output ,$output.length,$result |Out-File C:\Scripts\files.csv -append

  }

  # enumerate folders

  foreach ($folder in $web.Folders)
  {

  EnumPages $web.URL $folder

  }


   }



$site.Dispose(); ##ENFORCED DISPOSAL!!!    


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>