I want to get all the list URL from SharePoint 2013 using PowerShell CSOM.
Some one could suggest on this?
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityI want to get all the list URL from SharePoint 2013 using PowerShell CSOM.
Some one could suggest on this?
Below is my demo code for your reference:
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$loginname="Contoso\administrator"
$pwd="password"
$siteUrl="http://sp13/sites/michael"
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$Ctx.Credentials = New-Object System.Net.NetworkCredential($loginname, $pwd)
$lists=$Ctx.Web.Lists
$Ctx.load($lists)
$Ctx.ExecuteQuery()
foreach($list in $lists){
$Ctx.Load($list.RootFolder)
$Ctx.ExecuteQuery()
$listurl="http://sp13"+$list.RootFolder.ServerRelativeUrl
write-host $listurl
}
Check below code:
param
(
[string] $URL,
[boolean] $WriteToFile = $true
)
#Get all lists in farm
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Counter variables
$webcount = 0
$listcount = 0
if($WriteToFile -eq $true)
{
$outputPath = Read-Host "Outputpath (e.g. C:directoryfilename.txt)"
}
if(!$URL)
{
#Grab all webs
$webs = (Get-SPSite -limit all | Get-SPWeb -Limit all -ErrorAction SilentlyContinue)
}
else
{
$webs = Get-SPWeb $URL
}
if($webs.count -ge 1 -OR $webs.count -eq $null)
{
foreach($web in $webs)
{
#Grab all lists in the current web
$lists = $web.Lists
Write-Host "Website"$web.url -ForegroundColor Green
if($WriteToFile -eq $true){Add-Content -Path $outputPath -Value "Website $($web.url)"}
foreach($list in $lists)
{
$listcount +=1
Write-Host " – "$list.Title
if($WriteToFile -eq $true){Add-Content -Path $outputPath -Value " – $($list.Title)"}
}
$webcount +=1
$web.Dispose()
}
#Show total counter for checked webs & lists
Write-Host "Amount of webs checked:" $webcount
Write-Host "Amount of lists:" $listcount
}
else
{
Write-Host "No webs retrieved, please check your permissions" -ForegroundColor Red -BackgroundColor Black
}
Source: Get SharePoint lists by using PowerShell
With some little modifications in above code you can get all the required list details.
Additional resources: