Hide Document Library or Lists using PowerShell in SharePoint 2016/2013

In this article, I would like to excel in your PowerShell scripting to hide the document library/list in both SharePoint 2016/2013 and SharePoint Online.

In my current project client want to upload some of the confidential documents and want to hide the library. Also, he wants to ensure that no user looks at the document though they navigate with URL. Step1 I have implemented the below script to hide the document library from site contents in SharePoint 2013.

PowerShell Script to Hide List or Document Library in SharePoint 2016/2016

The below script is to hide the list/library in SharePoint 2016/2013. You can run debug and test PowerShell script using Windows PowerShell ISE.

function ShowOrHideListLibs($strSiteUrl, $strLstName, $boolHideValue)
#Get Web Object
$objWeb = Get-SPWeb $strSiteUrl
#Get the List Object
$objList = $objWeb.Lists[$strLstName]
#Set list / library the Hidden Property to show or hide
$objList.Hidden = $boolHideValue
Write-Host $strLstName + IIf ($showHideValue -eq $true) "Hidden successfully!" "Enabled/shown successfully!"
catch {
write-host "Could not find web" -foregroundcolor red

How it works?

Open PowerShell with run as administrator and run the script by providing the below 3 required parameters:

  • SharePoint Site URL
  • SharePoint Library Name
  • Flag bit value True -> To Hide the document library False -> To show the document library.


  • ShowOrHideListLibs <<Site URL>> << List/Library Name>> << Flag bit value >>
  • #Send the parameters as site URL, List/Library name, $true — To Hide /$false — To Show
  • ShowOrHideListLibs “http://Sharepoint2013:12345/” “User Loan Reports” $true

As soon as I completed the script I just want to enhance a step further to extent the scope to SharePoint Online.

The below script works for SharePoint Online:

#Including SharePoint Client side assemblies
#Reading User-ID and Password to connect SharePoint Online Site
$strUserId = Read-Host "Enter the username of SPO (eg. userName@OnlySharePoint2013.onmicrosoft.com)"
$strPassword = Read-Host "Please enter the password for $($strUserId)" -AsSecureString
#Setup Credentials to connect
$ObjCreds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($strUserId,$strPassword)
function ShowHideList($strSiteCollURL, $strLstName, $boolHidenVal)
#Bind to site collection
$ObjContext = New-Object Microsoft.SharePoint.Client.ClientContext($strSiteCollURL)
$ObjContext.Credentials = $ObjCreds
#Get the List
$ObjList = $ObjContext.Web.Lists.GetByTitle($strLstName)
$ObjList.Hidden = $boolHidenVal
Write-Host $strLstName + IIf ($boolHidenVal -eq $true) "Hidden successfully!" "Enabled/shown successfully!"

Like as SharePoint online execution we can execute the same from SharePoint PowerShell window / you can install SharePoint online PowerShell on window on your local machine and execute the script.

Read some PowerShell tutorials:

I hope this helps, happy development in SharePoint !!! You will get to know how to hide list or document library using PowerShell in SharePoint 2016/2013.