I need a PowerShell script that loop through a site collection and list down all the list title in excel format
3 Answers
Try the below code,
Add-PSSnapin Microsoft.Sharepoint.Powershell
$site = Get-SPSite "SiteURL"
$sitelists = foreach ($web in $site.AllWebs) {
foreach($list in $web.lists){ $list }}
$sitelists |select Title | Export-CSV C:\liststitles.csv
Remove-PsSnapin Microsoft.SharePoint.PowerShell
-
hi,Thanks for the reply. for retreving list properties and exporting to excel i hav ebeen usign the below code: function getListProperties ($spweb) { $sitelists= foreach ($spList in $spweb.Lists | Where {$_.Title -eq "SampleList"}) { Write-Host "List found in: $($spweb.Url)" $spList.PSObject.Properties | Select-Object Name,Value } $listpropsub= foreach ( $subweb in $spweb.Webs) { getListProperties $subweb } } $listpropsub|select getListProperties|Export-CSV C:\listspropsubtitles.csv.Itsnot showing any error but data is not dispaye din excel.– priyaJan 7, 2014 at 7:02
-
@priya, what data is not displyed in the CSV file, are you getting all the list names in the generated CSV file.? Jan 7, 2014 at 7:09
here is very good script on technet, which will list all Lists in a given site collection as table farm. you can export it to csv...
i.e get-splists | Export-CSV C:\liststitles.csv
-
Hi, am gettign some error like Get-SPlists is not a command. I added pssnapin in my code. Still error is coming. ALso let me know if i want to retreive list properties in excel whats the command?– priyaJan 7, 2014 at 5:30
-
1did you execute the powershell script which mentioned in the post...this is custom command...on that blog he has reference to technet, so download the PS file and run it first then you will able to run the get-lists command.gallery.technet.microsoft.com/ScriptCenter/…– Waqas Sarwar MVP ♦Jan 7, 2014 at 5:34
Maybe this can help you. It will give your all list from site. Also you can save list names to a file. I found this code from net; but I couldn't remember now where I found. I'm using this code and it works perfect.
param
(
[string] $URL="http://SiteURL",
[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:\directory\filename.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
}