How To Add A View To The List Using PowerShell In SharePoint Online

Prerequisites:

SharePoint Online Management Shell: https://www.microsoft.com/en-us/download/details.aspx?id=35588

PnP – PowerShell Cmdlets: https://github.com/officedev/pnp-powershell/releases

PowerShell Script:

Open SharePoint Online Management Shell and execute the following script.

  1. ## Connects to a SharePoint Site  
  2. Connect-SPOnline -Url https://c986.sharepoint.com -Credentials (Get-Credential)  
  3.   
  4. ## Syntax: Add-SPOView -Title <String> [-Query <String>] -Fields <String[]> [-ViewType <ViewType>] [-RowLimit <UInt32>] [-Personal [<SwitchParameter>]] [-SetAsDefault [<SwitchParameter>]] [-Paged [<SwitchParameter>]] [-Web <WebPipeBind>] -List <ListPipeBind>  
  5. ## Add a view to the list  
  6. Add-SPOView -List "Custom" -Title "My Test View" -Fields "Title","Modified"  
  7.   
  8. ##Disconnects the context  
  9. Disconnect-SPOnline