How to Hide a List View in SharePoint using PowerShell?
Requirement: 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 by hiding it 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
}
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?
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?