How to Modify SharePoint List View using SharePoint Online Powershell?

Hello SharePointers,

Below is the piece of Sharepoint Online Powershell code to modiy Sharepoint List view.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”

$siteUrl = “https://mytenant.sharepoint.com/sites/site”

$username = “admin@tenant.onmicrosoft.com”

$password = Read-Host -Prompt “Enter password” -AsSecureString

$context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)

$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)

$context.Credentials = $credentials

$listname = $context .get_web().get_lists().getByTitle(‘MyCustomList’);

$Defaultview = $listname .DefaultView

$DefaultView.ViewFields.Add(“Employee Address”)

$DefaultView.ViewFields.Add(“Employee Name”)

$DefaultView.ViewFields.Add(“Employee Department”)

$DefaultView.Update()

$context.ExecuteQuery()

Happy Sharepointing Folks 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *