GitHub Icon Image

Hide SharePoint list from Site Contents

Summary

If you need to hide the SharePoint list from the UI this simple PowerShell script will hide a specific list from the site contents. This will prevent users from easily accessing the list while, for example, you are still setting it up.

  • CLI for Microsoft 365 with PowerShell
  • Microsoft 365 CLI with Bash
  • PnP PowerShell
$listName = "listName"
$site = "https://contoso.sharepoint.com/"

m365 login
$list = m365 spo list get --webUrl $site -t $listName -o json | ConvertFrom-Json
m365 spo list set --webUrl $site -i $list.Id -t $listName --hidden true

Check out the CLI for Microsoft 365 to learn more at: https://aka.ms/cli-m365

#!/bin/bash

# requires jq: https://stedolan.github.io/jq/

listName="listName"
site=https://contoso.sharepoint.com/

m365 login
listId=$(m365 spo list get --webUrl $site -t "$listName" -o json | jq ".Id")
m365 spo list set --webUrl $site -i $listId -t $listName --hidden true

Check out the CLI for Microsoft 365 to learn more at: https://aka.ms/cli-m365

$listName = "listname"
$site = "https://contoso.sharepoint.com"

Connect-PnPOnline -url $site -Interactive
$list = Get-PnPList -Identity $listName
Set-PnPList -Identity $list -Hidden:$true

Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell

Source Credit

Sample first appeared on Hide SharePoint list from Site Contents | CLI for Microsoft 365

Contributors

Author(s)
David Ramalho
Leon Armston

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Back to top Script Samples
Generated by DocFX with Material UI