List custom fields from SharePoint Lists or libraries
Summary
This sample script may help to identify any custom columns/fields created in SharePoint lists or libraries.
Implementation
- Open Windows PowerShell ISE
- Create a new file
- Write a script as given below
- Update the
$siteUrl
,$ReportOutput
and optionally update$SystemFlds
&$SystemLists
to remove any values you would like to include in the report
# Connect to SharePoint site
$siteUrl = "https://contoso.sharepoint.com/teams/d-app"
Connect-PnPOnline -Url $siteUrl -Interactive
$dateTime = (Get-Date).toString("dd-MM-yyyy")
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
$ReportOutput = "FieldsReports-" + $dateTime + ".csv"
$OutPutFieldsFile = $directorypath + "\Logs\"+ $ReportOutput
#Arry to Skip OOB Fields
$SystemFlds = @(
"Compliance Asset Id","Body","Expires","ID","Content Type","Modified","Created","Created By","Modified By","Version","Attachments","Edit","Type","Item Child Count","Folder", "Child Count","App Created By","App Modified By", "Name","Checked Out To","Check In Comment","File Size","Source Version (Converted Document)","Source Name (Converted Document)","Location","Start Time","End Time","Description","All Day Event","Recurrence","Attendees","Category","Resources","Free/Busy","Check Double Booking","Enterprise Keywords", "Last Updated","Parent Item Editor","Parent Item ID","Last Reply By","Question","Best Response","Best Response Id", "Is Featured Discussion","E-Mail Sender","Replies","Folder Child Count","Discussion Subject","Reply","Post","Threading","Posted By", "Due Date","Assigned To","File Received","Number Of Setups","Notes/Comments","Task_Status","Is Approval Required","Approver","Approver Comments","Approval Date","Documents", "Order","Role","Person or Group","Location", "Predecessors","Priority","Task Status","% Complete","Start Date","Completed","Related Items", "Background Image Location","Link Location","Launch Behavior","Background Image Cluster Horizontal Start","Background Image Cluster Vertical Start", "First Name","Full Name","Email Address","Company","Job Title","Business Phone","Home Phone","Mobile Number","Fax Number","Address","City","State/Province","ZIP/Postal Code","Country/Region","Web Page","Notes","Name","Order","Role", "Color Tag", "Label setting", "Retention label", "Retention Label Applied", "Label applied by", "Item is a Record" ,"Comment Count","Like Count","Sensitivity", "Copy Source","Title"
)
#Arry to Skip System Lists and Libraries
$SystemLists = @(
"Converted Forms", "Master Page Gallery", "Customized Reports", "Form Templates", "List Template Gallery", "Theme Gallery", "Apps for SharePoint", "Reporting Templates", "Solution Gallery", "Style Library", "Web Part Gallery", "Site Assets", "wfpub", "Site Pages", "Images", "MicroFeed", "Pages"
)
#Get all lists from the site
$FieldsCollection = @()
$lists = Get-PnPList | Where {$_.Hidden -eq $false -and $SystemLists -notcontains $_.Title } | ForEach-Object {
$list = $_.Title
Get-PnPField -List $list | Where {$_.Hidden -eq $false -and $SystemFlds -notcontains $_.Title } | ForEach-Object {
$ExportField = New-Object PSObject
$ExportField | Add-Member -MemberType NoteProperty -name "List" -value $list
$ExportField | Add-Member -MemberType NoteProperty -name "FieldName" -value $_.Title
$FieldsCollection += $ExportField
}
}
#Export to CSV
$FieldsCollection | Export-Csv -Path $OutPutFieldsFile -NoTypeInformation
#Disconnect from SharePoint site
Disconnect-PnPOnline
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?
Contributors
Author(s) |
---|
Reshmee Auckloo |
Ganesh Sanap |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.