SharePoint Online: How to Hide a List or Library using PowerShell?
Requirement: Hide a list or library from the SharePoint Online site.
How to hide a SharePoint list from users by setting permissions?
You can also hide a SharePoint Online list or document library by setting its permissions so that only specific users can access it.
- Go to the List or Library settings page >> Click on the Permissions for this list link.
- Click on the ‘Stop Inheriting Permissions’ button. This will break the permission inheritance from the parent site, and you’ll be able to set unique permissions for the list or library.
- Finally, add only the users who should have access to the list or library, and remove all other users.
Once you are done with these changes, the list or library will be hidden from view for all users who don’t have permission to access it. Users with admin permissions will be able to see and access the hidden list or library, BTW! More info on setting up unique permissions to a SharePoint List or Document library: SharePoint Online: Grant Permission to List or Library using PowerShell
SharePoint Online: Hide a Document Library using PowerShell
We wanted to hide the config list in SharePoint Online for a custom application to prevent edits or deletions. How to hide a list in SharePoint Online? There are many ways to hide a SharePoint Online list. Here is the PowerShell CSOM script to create hidden lists in SharePoint Online:
#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/sites/sales/"
$LibraryName="ProjectConfig"
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#Get the web and Library
$Web=$Ctx.Web
$List=$web.Lists.GetByTitle($LibraryName)
#Hide the list
$List.Hidden = $True
$List.Update()
$Ctx.ExecuteQuery()
Write-host -f Green "List hidden Successfully!"
}
Catch {
write-host -f Red "Error hiding List: " $_.Exception.Message
}
Although the list is hidden from the site contents page, Everything will work as usual in the list, and you can still access it via the list URL.
SharePoint Online: Hide List using PnP PowerShell
Once you execute this script, the given list is immediately hidden from the site contents page. However, The list can be accessed via URL, and all the operations on that list will work as usual. Here is how to hide a SharePoint list from all users:
#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/Sales"
$ListName ="AppConfig"
#Connect PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#SharePoint Online Hide a List
Set-PnPList -Identity $ListName -Hidden $True
To make a list visible again, just set the value of the “hidden” flag to “False”. We can’t directly create a hidden list in SharePoint Online, but we can set its property hidden once added.
SharePoint Online Hidden List using SharePoint Designer
We can also use SharePoint Designer to mark a list hidden from the browser. Read more here: How to hide a list in SharePoint?
How to view hidden lists in SharePoint Online?
SharePoint Online and its applications store configuration data with certain hidden lists. E.g., “Access Requests”, “Composed Looks”, “User Information List”, etc. To get all hidden lists in SharePoint Online, use this PowerShell script:
#Connect to PnP Online
Connect-PnPOnline -Url "https://crescent.sharepoint.com/sites/marketing" -Interactive
#Get Hidden Lists and Libraries
Get-PnPList | Where { $_.Hidden -eq $true}
I wonder, If there is a way to get all hidden lists in a SharePoint Online site..
Sure, You can use: Get-PnPList | Where { $_.Hidden -EQ $True}