Requirement: SharePoint Online PowerShell to Get All List Fields.
How to Get List Fields in SharePoint Online?
If you navigate to list settings, under "Columns" section, you'll find all fields of the particular list.
SharePoint Online: PowerShell to Get All List Fields
Lets use PowerShell to get list field names and internal names.
SharePoint Online: Get All Fields of a List and Export to CSV
Lets get all list fieldsand export them to a CSV file.
How to Get List Fields in SharePoint Online?
If you navigate to list settings, under "Columns" section, you'll find all fields of the particular list.
SharePoint Online: PowerShell to Get All List Fields
Lets use PowerShell to get list field names and internal names.
#Load SharePoint CSOM Assemblies
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"
#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ListName="Projects"
#$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 and list fields
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.Load($List.Fields)
$Ctx.ExecuteQuery()
#Iterate through each field in the list
Foreach ($Field in $List.Fields)
{
#Skip System Fields
if(($Field.ReadOnlyField -eq $False) -and ($Field.Hidden -eq $False))
{
Write-Host $Field.Title : $Field.InternalName
}
}
SharePoint Online: Get All Fields of a List and Export to CSV
Lets get all list fieldsand export them to a CSV file.
#Load SharePoint CSOM Assemblies
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 to Get all fields from a SharePoint Online list or library
Function Get-ListFields()
{
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
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.Load($List.Fields)
$Ctx.ExecuteQuery()
#Array to hold result
$FieldData = @()
#Iterate through each field in the list
Foreach ($Field in $List.Fields)
{
Write-Host $Field.Title `t $Field.Description `t $Field.InternalName `t $Field.Id `t $Field.TypeDisplayName
#Send Data to object array
$FieldData += New-Object PSObject -Property @{
'Field Title' = $Field.Title
'Field Description' = $Field.Description
'Field ID' = $Field.Id
'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="https://crescent.sharepoint.com"
$ListName="Projects"
$CSVLocation ="C:\Temp\ListFields.csv"
#Call the function to get all list fields
Get-ListFields -SiteURL $SiteURL -ListName $ListName | Export-Csv $CSVLocation -NoTypeInformation