Skip to content

Commit cfb6dad

Browse files
authored
Merge pull request #1016 from ojopiyo:patch-39
Update README.md
2 parents 44aca7b + ba12cee commit cfb6dad

2 files changed

Lines changed: 198 additions & 9 deletions

File tree

‎scripts/spo-hide-list-from-site-contents/README.md‎

Lines changed: 191 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,181 @@
1-
2-
31
# Hide SharePoint list from Site Contents
42

53
## Summary
64

7-
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.
8-
5+
These scripts hide a SharePoint Online list from Site Contents using PnP PowerShell or CLI for Microsoft 365. The updated PnP PowerShell version also generates an audit record of the administrative action.
6+
7+
The updated version uses PnP PowerShell with certificate-based application authentication to connect to a specified SharePoint Online site, sets the target list's Hidden property to $true, and exports an audit record containing the action date, executing user, site URL, list name, and action performed.
8+
9+
The generated CSV report provides a lightweight, timestamped record suitable for operational auditing and change tracking.
10+
11+
## Why It Matters
12+
13+
SharePoint lists may contain application configuration, integration data, staging information, or other administrative content that should not be exposed through normal SharePoint navigation.
14+
15+
A common administrative scenario is hiding a configuration list from the standard SharePoint user interface while retaining the list and its data for application or administrative use.
16+
17+
This script provides a repeatable approach to:
18+
19+
- Hide a designated SharePoint list without deleting its contents.
20+
- Perform the change using non-interactive certificate authentication.
21+
- Record who performed the action and when it occurred.
22+
- Produce a timestamped audit file for operational records or change management.
23+
24+
25+
# [PnP PowerShell Updated (with audit)](#tab/pnppsv2)
26+
27+
## Prerequisites
28+
29+
The following prerequisites apply to the updated PnP PowerShell version with audit reporting.
30+
31+
- PnP.PowerShell module
32+
- A Microsoft Entra ID application registration
33+
- Certificate-based authentication configured for the application
34+
- Appropriate SharePoint permissions granted to the application
35+
- The certificate corresponding to $ThumbPrint available to the account executing the script
36+
- Access to the target SharePoint site
37+
- The target list must already exist
38+
39+
## Configuration
40+
41+
For the updated PnP PowerShell version, configure the variables at the beginning of the script:
42+
43+
| Variable | Description |
44+
| ----------------- | ---------------------------------------------------------- |
45+
| `$ClientID` | Azure AD Application (Client) ID |
46+
| `$ThumbPrint` | Certificate thumbprint |
47+
| `$Tenant` | Microsoft 365 tenant name (e.g. `contoso.onmicrosoft.com`) |
48+
| `$SiteUrl` | Your Site URL i.e. `https://contoso.sharepoint.com/sites/A`|
49+
| `$ListName` | Your List Name i.e. `ListName` |
50+
51+
The script can then be executed from a PowerShell session or incorporated into an administrative automation process.
52+
53+
The executing identity must have sufficient permissions to connect to the SharePoint site and modify the target list.
54+
55+
```powershell
56+
57+
# ============================================================
58+
# CONFIGURATION
59+
# ============================================================
60+
61+
$ClientID = "xxxxxxxxxxxxxxxxxxxxx"
62+
$ThumbPrint = "xxxxxxxxxxxxxxxxxxxxx"
63+
$Tenant = "contoso.onmicrosoft.com"
64+
65+
$SiteUrl = "https://contoso.sharepoint.com/sites/A"
66+
$ListName = "AppConfig"
67+
68+
$OutputFolder = "C:\Temp\SharePointListAudit"
69+
70+
if (-not (Test-Path -LiteralPath $OutputFolder)) {
71+
New-Item -Path $OutputFolder -ItemType Directory -Force | Out-Null
72+
}
73+
74+
$TimeStamp = Get-Date -Format "yyyyMMdd_HHmmss"
75+
$CsvFile = Join-Path $OutputFolder "SharePointListAudit_$TimeStamp.csv"
76+
77+
# ============================================================
78+
# WHO AND WHEN
79+
# ============================================================
80+
81+
$ActionBy = $env:USERNAME
82+
$ActionDate = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
83+
84+
# ============================================================
85+
# CONNECT
86+
# ============================================================
87+
88+
Connect-PnPOnline `
89+
-Url $SiteUrl `
90+
-ClientId $ClientID `
91+
-Thumbprint $ThumbPrint `
92+
-Tenant $Tenant
93+
94+
# ============================================================
95+
# HIDE SHAREPOINT LIST
96+
# ============================================================
97+
98+
Set-PnPList -Identity $ListName -Hidden $true
99+
100+
# ============================================================
101+
# CREATE AUDIT RECORD
102+
# ============================================================
103+
104+
[PSCustomObject]@{
105+
ActionDate = $ActionDate
106+
ActionBy = $ActionBy
107+
SiteUrl = $SiteUrl
108+
ListName = $ListName
109+
Action = "Hide List"
110+
} | Export-Csv `
111+
-Path $CsvFile `
112+
-NoTypeInformation `
113+
-Encoding UTF8
114+
115+
# ============================================================
116+
# DISCONNECT
117+
# ============================================================
118+
119+
Disconnect-PnPOnline
120+
121+
Write-Host "List '$ListName' hidden successfully."
122+
Write-Host "Audit report: $CsvFile"
123+
124+
```
125+
126+
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
127+
128+
## Output
129+
130+
The updated PnP PowerShell version creates a timestamped CSV file in the configured output directory:
131+
132+
> SharePointListAudit_yyyyMMdd_HHmmss.csv
133+
134+
Example record:
135+
136+
### CSV Report Fields
137+
138+
| Field | Description |
139+
| ----------------------- | ---------------------------------------------------------- |
140+
| `ActionDate` | Date and time the operation was performed |
141+
| `ActionBy` | Windows/PowerShell environment username |
142+
| `SiteUrl` | SharePoint Online site containing the list |
143+
| `ListName` | List modified by the script |
144+
| `Action` | Administrative action performed |
145+
146+
## Notes
147+
148+
- Set-PnPList -Hidden $true hides the list; it does not delete the list or its data.
149+
- The script assumes the target list already exists.
150+
- $env:USERNAME identifies the local execution context, not necessarily the identity represented by the Entra ID application used for SharePoint authentication.
151+
- The output directory is created automatically if it does not exist.
152+
- Disconnect-PnPOnline terminates the PnP PowerShell connection after the operation.
153+
- For production automation, avoid storing client IDs, certificate material, or other credentials directly in scripts where possible.
154+
- Consider adding structured error handling and logging if this script is used as part of a larger operational process.
155+
156+
## Refactoring Notes
157+
158+
The updated version adds an alternative using the **PnP PowerShell module (PnP.PowerShell)** with **certificate-based app-only authentication**. The original PnP PowerShell and CLI for Microsoft 365 scripts remain available in their own tabs.
159+
160+
The refactoring also introduces explicit configuration variables, execution metadata, output/audit reporting, structured sections, and clearer operational feedback.
161+
162+
### Improvements Made (v2.0)
163+
164+
| Area | Initial Version | Updated Version | Improvement |
165+
| ------------------------------- | -------------------------------------- | -------------------------------------------------------------------- | ---------------------------------------------------------- |
166+
| `Authentication` | m365 login / interactive session | Connect-PnPOnline with Client ID, certificate thumbprint and tenant | Supports unattended/service-style execution |
167+
| `SharePoint interaction` | m365 spo list set | Set-PnPList | Uses native PnP PowerShell cmdlets |
168+
| `Configuration` | Site/list values embedded near the top | Dedicated configuration section | Easier to maintain and reuse |
169+
| `Authentication configuration` | Not explicitly defined | Client ID, Thumbprint and Tenant variables | Makes authentication requirements explicit |
170+
| `Output` | Console only | Timestamped CSV audit file | Provides persistent execution history |
171+
| `Audit information` | None | User, date/time, site, list and action | Improves traceability |
172+
| `Output directory` | None | Automatically created if required | Reduces manual setup |
173+
| `File naming` | None | Timestamped audit filename | Prevents reports from overwriting each other |
174+
| `Script structure` | Simple linear script | Clearly separated functional sections | Improves readability and maintenance |
175+
| `Connection lifecycle` | m365 logout | Disconnect-PnPOnline | Explicitly closes the PnP connection |
176+
| `User feedback` | Minimal | Success message plus audit-file location | Makes execution outcome clearer |
177+
| `Encoding` | Not applicable | UTF-8 CSV output | Provides consistent report encoding |
178+
9179
# [PnP PowerShell](#tab/pnpps)
10180

11181
```powershell
@@ -52,17 +222,30 @@ m365 spo list set --webUrl $siteUrl --title $listName --hidden true
52222
m365 logout
53223
54224
```
225+
55226
[!INCLUDE [More about CLI for Microsoft 365](../../docfx/includes/MORE-CLIM365.md)]
56227

228+
57229
***
58230

231+
232+
59233
## Contributors
60234

61-
| Author(s) |
235+
|Author(s)|
62236
|-----------|
63-
| Leon Armston |
64-
| [Ganesh Sanap](https://ganeshsanapblogs.wordpress.com/about) |
237+
|Leon Armston|
238+
|[Ganesh Sanap](https://ganeshsanapblogs.wordpress.com/about)|
239+
|[Josiah Opiyo](https://github.com/ojopiyo)|
240+
241+
*Built with a focus on automation, governance, least privilege, and clean Microsoft 365 tenants - helping M365 admins gain visibility and reduce operational risk.*
242+
243+
## Version history
65244

245+
|Version|Date|Comments|
246+
|-------|----|--------|
247+
|1.0|May 09, 2023|Initial release|
248+
|2.0|October 03, 2026|Refactored version|
66249

67250
[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
68-
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-hide-list-from-site-contents" aria-hidden="true" />
251+
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-hide-list-from-site-contents" aria-hidden="true" />

‎scripts/spo-hide-list-from-site-contents/assets/sample.json‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"title": "Hide SharePoint list from Site Contents",
88
"url": "https://pnp.github.io/script-samples/spo-hide-list-from-site-contents/README.html",
99
"creationDateTime": "2020-08-23",
10-
"updateDateTime": "2023-05-09",
10+
"updateDateTime": "2026-10-08",
1111
"shortDescription": "Hide the SharePoint list from the UI this script will hide a specific list from the site contents",
1212
"longDescription": null,
1313
"products": [
@@ -47,6 +47,12 @@
4747
}
4848
],
4949
"authors": [
50+
{
51+
"gitHubAccount": "ojopiyo",
52+
"company": "",
53+
"pictureUrl": "https://github.com/ojopiyo.png",
54+
"name": "Josiah Opiyo"
55+
},
5056
{
5157
"gitHubAccount": "ganesh-sanap",
5258
"company": "",

0 commit comments

Comments
 (0)