How to Hide a List View in SharePoint using PowerShell?

Requirement: Hide a List View in SharePoint.

sharepoint hide a list view

Sometimes you may need to hide a list view in SharePoint to restrict access to specific data from users. In this article, we will discuss how to hide a list view in SharePoint.

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
$SiteURL="https://intranet.crescent.com"
$ListName="Projects"
$ViewName="All Projects"

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

#Hide the list view
$View.Hidden=$true
$View.Update()

Write-host "List View Hidden from users!"

This hides the list view from users from the view drop-down and 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= "https://crescent.sharepoint.com/"
$ListName="Projects"
$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
    $List=$Ctx.Web.Lists.GetByTitle($ListName)
    
    #Get the List View
    $ListView = $List.views.GetByTitle($ViewName)
    $Ctx.load($ListView)
    $Ctx.executeQuery()

    #Hide SharePoint Online List view
    $ListView.Hidden = $True
    $ListView.Update()
    $Ctx.ExecuteQuery()

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

PnP PowerShell to Hide a View in SharePoint Online

Use the Set-PnPView cmdlet to set view properties!

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Retail"
$ListName = "Projects"
$ViewName = "All Projects"

#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -Interactive

#Hide the List View
Set-PnPView -List $ListName -Identity $ViewName -Values @{Hidden =$True}

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

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

2 thoughts on “How to Hide a List View in SharePoint using PowerShell?

  • is it possible to hide the view in SharePoint 2013 based on SharePoint groups? For instance hide the view for all ‘Site Visitors’ SharePoint group?

    Reply
    • Target Audience allows this

      Reply

Leave a Reply

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