SharePoint Online: Get All Fields from List View using PowerShell

Requirement: Get all fields from a SharePoint Online 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= ""
$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
    #Get the List View
    $ListView = $List.views.GetByTitle($ViewTitle)

    #Get all fields from the list view
    $ViewFields= $ListView.ViewFields

    #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

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