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?

To view all columns included in a SharePoint Online list view, click on the little down-arrow next to any column in the view >> Choose Column Settings >> Show/hide columns.

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:

#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 is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply