In this article, you will learn how we can retrieve, create, update or delete list views using CSOM with PowerShell. This is mainly focused on using PowerShell scripts for SharePoint online sites.
First we will see how we can get the existing views available on the SharePoint site. The steps followed here are very similar to the steps following CSOM or JSOM programming.
Initialize context object with the site URL parameter. Then initialize the SP Online Credentials with the above parameters and set it to the context.
Then access the list using the context and then the views from the list, load the objects and execute the query.
Loop through the result object and get the necessary view information.
$siteURL = ""
$userId = ""
$pwd = Read-Host -Prompt "Enter password" -AsSecureString
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd)
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
$ctx.credentials = $creds
$list = $ctx.web.Lists.GetByTitle("TestList")
$views = $list.views
foreach($view in $views)
write-host "$($_.Exception.Message)" -foregroundcolor red
This will get all the view names available for the list on the site. Next, we will see how we can get one particular list on the site.