SharePoint Online: Get All Fields from a List View using PowerShell

Requirement: Get all fields from a SharePoint Online List View.

How to Get Columns from a SharePoint Online View?

Retrieving all fields from a SharePoint Online list view can be useful for various purposes, such as analyzing column usage, managing fields, or exporting data to external systems. This article will guide you through the steps to get all fields from a SharePoint Online list view.

To view all columns included in a SharePoint Online list view, do the following:

  1. Go to the list for which you want to get all fields from a view.
  2. Click the little down arrow next to any column in the view >> Choose Column Settings >> Show/hide columns. All fields included in the view will be listed in this section.
get columns from view sharepoint online

You can also use: Edit current View to get fields included in the particular list view.

SharePoint Online: PowerShell to Get All Fields from a List View

This PowerShell script gets all fields from a given list view in SharePoint Online:

#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"
   
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/"
$ListName="Projects"
$ViewTitle ="All Items" 

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
 
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
   
    #Get the List
    $List=$Ctx.Web.Lists.GetByTitle($ListName)
    
    #Get the List View
    $ListView = $List.views.GetByTitle($ViewTitle)
    $Ctx.load($ListView)
    $Ctx.executeQuery()

    #Get all fields from the list view
    $ViewFields= $ListView.ViewFields
    $Ctx.Load($ViewFields)
    $Ctx.ExecuteQuery()

    #Loop through all the fields of the view
    ForEach($ViewField in $ViewFields)
    {
        #Get the Field Name
        Write-Host $ViewField
    }    
}
Catch {
    write-host -f Red "Error Getting List View Fields!" $_.Exception.Message
}

PnP PowerShell to Get All Columns from a SharePoint Online View

Here is the PnP PowerShell to get all fields from a List view:

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/pmo"
$ListName = "Projects"
$ViewName = "Active Projects"

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive

    #Get the View
    $View = Get-PnPView -List $ListName -Identity $ViewName -Includes ViewFields
    
    #Get all Fields from the view - Internal Name
    $View.ViewFields
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *