Last active
October 2, 2020 16:16
-
-
Save nchambe/500b6b6c998e58e4eac538e2032ada96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | |
#See https://docs.microsoft.com/en-us/openspecs/sharepoint_protocols/ms-wssts/8bf797af-288c-4a1d-a14b-cf5394e636cf for all list template IDs. | |
#Replace the three variable values below with those you wish to use. | |
$ListTemplateId = 108 | |
$sites = Get-SPSite -WebApplication https://sharepoint.contoso.com -Limit ALL | |
$saveCSVLocation ="C:\Users\Public\Downloads\" | |
foreach($site in $sites) | |
{ | |
foreach($web in $site.AllWebs) | |
{ | |
foreach($list in $web.Lists) | |
{ | |
if ($list.BaseTemplate -eq $ListTemplateId) | |
{ | |
foreach($i in $list) | |
{ | |
#This displays findings as they're found in the PowerShell Window. | |
$ListData = @( | |
@{Site=$web.Title;ListName=$list.Title;URL=($web.Url + "/" + $i.DefaultView.Url)}) | % { New-Object object | Add-Member -NotePropertyMembers $_ -PassThru } | |
$ListData | |
#This creates the CSV file in your specified save location. | |
$SaveLocationFinal = ($saveCSVLocation +"SPListExport " + (Get-Date).ToString('yyyy-MM-dd hh') + ".csv") | |
write-Output ($web.Title + "," + $list.Title + "," + $web.Url + "/" + $i.DefaultView.Url) | Out-File $SaveLocationFinal -Append | |
} | |
} | |
} | |
} | |
} | |
#These two lines are just used as a final count and confirmation in your PowerShell window to let you know what was found, and confirm where the CSV export is saved. | |
$itemCount = Import-Csv $SaveLocationFinal -Header Site,ListName,URL | Measure-Object | Select-Object -expand count | |
write-host ($itemCount.ToString() + " lists of ID type " + $ListTemplateID.ToString() + " (" + $i.BaseTemplate + ") found. CSV data exported to " + $saveCSVLocation + ".") -ForegroundColor Green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment