How to Get All List Fields in SharePoint Online using PnP PowerShell?

Recently, one of my clients wanted to list all the column names from a SharePoint Online list. I tried PnP PowerShell to do it. In this tutorial, I will explain how to get all list fields in SharePoint Online using PnP PowerShell.

I will also show you how to get all the list columns, including out-of-box columns and custom columns, from the SharePoint Online list or document library.

Get All List Fields in SharePoint Online using PnP PowerShell

Here, I have a SharePoint list that has a few columns. You can see the output in the screenshot below:

Get All List Fields in SharePoint Online using PnP PowerShell

To get all column names from a specific list in the SharePoint Online site, use the Get-PnPField cmdlet.

$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive

$listName = "Employee Onboarding"
$fields = Get-PnPField -List $listName
foreach ($field in $fields) {
    Write-Host "Field Title: $($field.Title) - Internal Name: $($field.InternalName) - Type: $($field.TypeAsString)"
}

After you execute the above PowerShell script, you can see the list of columns from the SharePoint Online list. It also includes all the hidden columns, custom columns, and out-of-box columns. Check the screenshot below for your reference.

pnp powershell get list columns

Get Custom Columns from a SharePoint List using PnP PowerShell

Sometimes, you might just want to get the custom columns from the SharePoint Online list using PnP PowerShell.

Here is the complete PowerShell script.

$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive

$listName = "Employee Onboarding"
$fields = Get-PnPField -List $listName
$customFields = $fields | Where-Object { $_.CanBeDeleted -eq $true }
foreach ($field in $customFields) {
    Write-Host "Custom Field Title: $($field.Title) - Internal Name: $($field.InternalName) - Type: $($field.TypeAsString)"
}

I executed the above script; you can see the output in the screenshot below. It displays all the custom columns from the SharePoint Online list.

pnp powershell get all sharepoint list fields

Get Out-of-the-Box Columns from SharePoint List using PnP PowerShell

Now, it is time to show you how to out-of-the-box columns from a SharePoint Online list using PnP PowerShell.

Here is the complete PnP PowerShell.

$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive

$listName = "Employee Onboarding"
$fields = Get-PnPField -List $listName
$ootbFields = $fields | Where-Object { $_.CanBeDeleted -eq $false }
foreach ($field in $ootbFields) {
    Write-Host "OOTB Field Title: $($field.Title) - Internal Name: $($field.InternalName) - Type: $($field.TypeAsString)"
}

You can see the output in the screenshot below:

pnp powershell get all fields from SharePoint Online list

Here is the complete script for all the examples above.

$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"Connect-PnPOnline -Url $siteUrl -Interactive$listName = "Employee Onboarding"

# Retrieve all fields
$fields = Get-PnPField -List $listName

# Display all fields
Write-Host "All Fields:"
foreach ($field in $fields) {
    Write-Host "Field Title: $($field.Title) - Internal Name: $($field.InternalName) - Type: $($field.TypeAsString)"
}

# Retrieve custom fields
$customFields = $fields | Where-Object { $_.CanBeDeleted -eq $true }
Write-Host "`nCustom Fields:"
foreach ($field in $customFields) {
    Write-Host "Custom Field Title: $($field.Title) - Internal Name: $($field.InternalName) - Type: $($field.TypeAsString)"
}

# Retrieve out-of-the-box fields
$ootbFields = $fields | Where-Object { $_.CanBeDeleted -eq $false }
Write-Host "`nOOTB Fields:"
foreach ($field in $ootbFields) {
    Write-Host "OOTB Field Title: $($field.Title) - Internal Name: $($field.InternalName) - Type: $($field.TypeAsString)"
}

Conclusion

In this tutorial, I have explained how to use PnP PowerShell to retrieve all column names from a SharePoint Online list, including custom and out-of-the-box columns.

You may also like the following tutorials:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.