I'm using ModernUI for SharePoint Online. I'd like to get all List and Library's ColumnName, Type, InternalName in my site by PnP PowerShell. I did some research myself, but I didn't understand, so I would appreciate it if you could teach me how to do it. Thank you for any information. Thank you.
2 Answers
1.Download SharePoint Online Management Shell.
2.Try below PowerShell as administrator.
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Function Get-SPOListFields()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ListName
)
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the List
$Lists = $Context.web.Lists
$Context.Load($Lists)
$Context.ExecuteQuery()
#Array to hold result
$FieldData = @()
ForEach($List in $Lists)
{
Foreach ($Field in $List.Fields)
{
Write-Host $List.Title `t $Field.Title `t $Field.InternalName `t
$Field.TypeDisplayName
#Send Data to object array
$FieldData += New-Object PSObject -Property @{
'List Title' = $List.Title
'Field Title' = $Field.Title
'Internal Name' = $Field.InternalName
'Type' = $Field.TypeDisplayName
'Schema' = $Field.SchemaXML
}
}
}
Return $FieldData
}
Catch {
write-host -f Red "Error Getting Fields from List!" $_.Exception.Message
}
}
#Set parameter values
$SiteURL="site collection URL"
$CSVLocation ="local drive"
#Call the function to get all list fields
$FieldData | Export-Csv $CSVLocation -NoTypeInformation
-
Thank you very much!! It works. But I'd like to do this for all List and Library. I don't want to specify a specific list. In that case, Do you have any script?– HyontaCommented Jan 1, 2021 at 11:54
-
Connect-PnPOnline https://tenantName.sharepoint.com/sites/siteName -PnPManagementShell
$lists = Get-PnPList -Includes Fields
foreach($list in $lists)
{
$list.Title
$list.Fields | select title,internalname,typeasstring
}
-
Thank you very much!! It works very well. What if I want to output the list name as well?– HyontaCommented Jan 2, 2021 at 8:13
-
Add
$list.Title
in theforeach
loop.– user6024Commented Jan 2, 2021 at 18:42 -
I did like this
$list.Fields | select title,internalname,typeasstring,$list.Title
. But I got listname just one.– HyontaCommented Jan 3, 2021 at 7:50