SharePoint Online: PowerShell to Update List View
Requirement: Update List View in SharePoint Online using PowerShell
SharePoint Online: PowerShell to Update List View
Lets apply a filter to "Active Projects" view to get all projects with "Project Status" field value as "Active"
Update View in SharePoint Online using PnP PowerShell
PnP PowerShell to Set View Type to "Tiles" in SharePoint Online
Here is an another example of updating view settings in SharePoint Online.
What other properties can be updated throgh PowerShell?
Related posts:
SharePoint Online: PowerShell to Update List View
Lets apply a filter to "Active Projects" view to get all projects with "Project Status" field value as "Active"
#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" #Function to Update List View in SharePoint Online Function Update-SPOListView($SiteURL, $ListName, $ViewName, $ViewQuery) { Try { #Get Credentials to connect $Cred= Get-Credential #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) #Get the List $List=$Ctx.Web.Lists.GetByTitle($ListName) #Get the view to update $View = $List.Views.GetByTitle($ViewName) $Ctx.ExecuteQuery() If($View -ne $NULL) { #Update the View Query $View.ViewQuery = $ViewQuery $View.Update() $Ctx.ExecuteQuery() Write-host "View Updated Successfully!" -f Green } else { Write-host "View '$ViewName' doesn't exist in the List!" -f Yellow } } Catch { write-host -f Red "Error:" $_.Exception.Message } } #Set parameter values $SiteURL = "https://crescenttech.sharepoint.com" $ListName ="Projects" $ViewName="Active Projects" $ViewQuery ="<Where><Eq><FieldRef Name = 'ProjectStatus' /><Value Type ='Choice'>Active</Value></Eq></Where>" #Call the function Update-SPOListView -SiteURL $SiteURL -ListName $ListName -ViewName $ViewName -ViewQuery $ViewQuery
Update View in SharePoint Online using PnP PowerShell
#Config Variables $SiteURL = "https://crescenttech.sharepoint.com" $ListName ="Projects" $ViewName="Active Projects" $ViewQuery ="<Where><Eq><FieldRef Name = 'ProjectStatus' /><Value Type ='Choice'>Active</Value></Eq></Where>" #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential) #Get the Client Context $Context = Get-PnPContext #Get the List View $View = Get-PnPView -Identity $ViewName -List $ListName #Update the view Query $View.ViewQuery = $ViewQuery $View.Update() $Context.ExecuteQuery()
PnP PowerShell to Set View Type to "Tiles" in SharePoint Online
Here is an another example of updating view settings in SharePoint Online.
#Parameters $SiteURL = "https://crescent.sharepoint.com/sites/marketing" $ListName = "Branding" $ViewName= "All Documents" #Connect to the Site Connect-PnPOnline -URL $SiteURL -UseWebLogin #Set View Properties Set-PnPView -List $ListName -Identity $ViewName -Values @{"ViewType2" = "TILES"}
What other properties can be updated throgh PowerShell?
- Aggregations
- AggregationsStatus
- ColumnWidth
- ContentTypeId
- CustomFormatter
- DefaultView
- DefaultViewForContentType
- EditorModified
- Formats
- Hidden
- IncludeRootFolder
- JSLink
- ListViewXml
- Method
- MobileDefaultView
- MobileView
- NewDocumentTemplates
- ObjectVersion
- Paged
- RowLimit
- Scope
- TabularView
- Tag
- Title
- Toolbar
- ViewData
- ViewJoins
- ViewProjectedFields
- ViewQuery
- VisualizationInfo
Related posts:
No comments:
Please Login and comment to get your questions answered!