How to Hide a SharePoint List or Library from the UI?

How to Hide a SharePoint List or Library from the UI?

SharePoint provides powerful collaboration features to users including lists and libraries, and while transparency is crucial, there are instances where hiding a list or library becomes essential for optimizing user experiences and/or maintaining data integrity. Example: Power Apps often relies on SharePoint lists as data sources. However, not all lists are meant for end users to view directly. By hiding lists or libraries from SharePoint UI, you can prevent end users from editing the data directly from SharePoint lists.

In this blog post, we’ll explore how to hide a SharePoint list or document library using PnP PowerShell & CLI for Microsoft 365 and view all hidden lists/libraries in SharePoint site using PnP PowerShell & CLI for Microsoft 365.

Hiding a SharePoint List or Library using PnP PowerShell

You can use below PnP PowerShell script to hide a SharePoint online list or document library from SharePoint UI (Site Contents page):

# SharePoint Online site URL
$siteUrl = Read-Host -Prompt "Enter your SharePoint online site URL (e.g https://contoso.sharepoint.com/sites/work)"

# Display name of SharePoint online list or document library
$listName = Read-Host -Prompt "Enter the display name of your SharePoint list or library (e.g My List)"

# Connect to SharePoint online site
Connect-PnPOnline -url $siteUrl -Interactive

# Hide SharePoint online list from UI
Set-PnPList -Identity $listName -Hidden $true

# Disconnect SharePoint online connection
Disconnect-PnPOnline

Hide a SharePoint List or Library using CLI for Microsoft 365

Use below CLI for Microsoft 365 script to hide a SharePoint list or document library from SharePoint UI:

# SharePoint Online site URL
$siteUrl = Read-Host -Prompt "Enter your SharePoint online site URL (e.g https://contoso.sharepoint.com/sites/work)"

# Display name of SharePoint online list or document library
$listName = Read-Host -Prompt "Enter the display name of your SharePoint list or library (e.g My List)"

# Get Credentials to connect
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
m365 login
}

# Hide SharePoint online list or library from UI (Site Contents)
m365 spo list set --webUrl $siteUrl --title $listName --hidden true

# Disconnect SharePoint online connection
m365 logout

View hidden lists/libraries in SharePoint site using PnP PowerShell

You can use below PnP PowerShell script to view all hidden lists and libraries in the given SharePoint site:

# SharePoint Online site URL
$siteUrl = Read-Host -Prompt "Enter your SharePoint online site URL (e.g https://contoso.sharepoint.com/sites/work)"

# Connect to SharePoint online site
Connect-PnPOnline -url $siteUrl -Interactive

# View all hidden lists/libraries in a SharePoint online site
Get-PnPList | Where-Object {$_.Hidden -eq $true}

# Disconnect SharePoint online connection
Disconnect-PnPOnline

View hidden lists/libraries in SharePoint site using CLI for Microsoft 365

Use below CLI for Microsoft 365 script to view all hidden lists and document libraries in the given SharePoint online site:

# SharePoint Online site URL
$siteUrl = Read-Host -Prompt "Enter your SharePoint online site URL (e.g https://contoso.sharepoint.com/sites/work)"

# Get Credentials to connect
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
m365 login
}

# Hide SharePoint online list or library from UI (Site Contents)
m365 spo list list --webUrl $siteUrl --properties "Id,Title,Url" --filter "Hidden eq true" | ConvertFrom-Json

# Disconnect SharePoint online connection
m365 logout

Learn more

Leave a comment