How to Hide a List View in SharePoint using PowerShell?

Requirement: Hide a List View in SharePoint

sharepoint hide a list view

How to Hide a SharePoint List View?

To hide a list view in SharePoint, use this PowerShell script.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Config variables
$ViewName="All Projects"

#Get the View
$Web = Get-SPWeb $SiteURL
$List = $Web.Lists[$ListName]
$View = $List.Views[$ViewName]

#Hide the list view

Write-host "List View Hidden from users!"

This hides the list view from users by hiding it from view drop down and from list settings. However, if you know the URL, you can directly hit and get the view page!

SharePoint Online: Hide a List View using PowerShell

Similarly, in SharePoint Online hide list view, here is the PowerShell script.

#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= ""
$ViewName ="All Projects" 

#Get Credentials to connect
$Cred = Get-Credential
Try {
    #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
    #Get the List View
    $ListView = $List.views.GetByTitle($ViewName)

    #Hide SharePoint Online List view
    $ListView.Hidden = $True

    Write-host -f Green "List View Hidden from users!"
Catch {
    write-host -f Red "Error Hiding List View!" $_.Exception.Message

This hides list view in SharePoint Online from all users. If you want to restrict a view to specific users or groups, use my another article: How to Set permission to SharePoint List View?

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