Skip to content

Commit ba12cee

Browse files
committed
Updated to credit and keep the old scripts, seperate to the updates.
1 parent 5d873c2 commit ba12cee

2 files changed

Lines changed: 75 additions & 9 deletions

File tree

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

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Hide SPO List using PnP PowerShell
1+
# Hide SharePoint list from Site Contents
22

33
## Summary
44

5-
This PowerShell script automates the process of hiding a SharePoint Online list and generating an audit record of the administrative action.
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.
66

7-
It 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.
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.
88

99
The generated CSV report provides a lightweight, timestamped record suitable for operational auditing and change tracking.
1010

@@ -21,8 +21,13 @@ This script provides a repeatable approach to:
2121
- Record who performed the action and when it occurred.
2222
- Produce a timestamped audit file for operational records or change management.
2323

24+
25+
# [PnP PowerShell Updated (with audit)](#tab/pnppsv2)
26+
2427
## Prerequisites
2528

29+
The following prerequisites apply to the updated PnP PowerShell version with audit reporting.
30+
2631
- PnP.PowerShell module
2732
- A Microsoft Entra ID application registration
2833
- Certificate-based authentication configured for the application
@@ -33,7 +38,7 @@ This script provides a repeatable approach to:
3338

3439
## Configuration
3540

36-
Configure the variables at the beginning of the script:
41+
For the updated PnP PowerShell version, configure the variables at the beginning of the script:
3742

3843
| Variable | Description |
3944
| ----------------- | ---------------------------------------------------------- |
@@ -47,8 +52,6 @@ The script can then be executed from a PowerShell session or incorporated into a
4752

4853
The executing identity must have sufficient permissions to connect to the SharePoint site and modify the target list.
4954

50-
# [PnP PowerShell](#tab/pnpps)
51-
5255
```powershell
5356
5457
# ============================================================
@@ -120,9 +123,11 @@ Write-Host "Audit report: $CsvFile"
120123
121124
```
122125

126+
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
127+
123128
## Output
124129

125-
A timestamped CSV file is created in the configured output directory:
130+
The updated PnP PowerShell version creates a timestamped CSV file in the configured output directory:
126131

127132
> SharePointListAudit_yyyyMMdd_HHmmss.csv
128133
@@ -150,7 +155,7 @@ Example record:
150155

151156
## Refactoring Notes
152157

153-
The original script was refactored from using the **CLI for Microsoft 365 (m365)** to using the **PnP PowerShell module (PnP.PowerShell)** with **certificate-based app-only authentication**.
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.
154159

155160
The refactoring also introduces explicit configuration variables, execution metadata, output/audit reporting, structured sections, and clearer operational feedback.
156161

@@ -171,6 +176,60 @@ The refactoring also introduces explicit configuration variables, execution meta
171176
| `User feedback` | Minimal | Success message plus audit-file location | Makes execution outcome clearer |
172177
| `Encoding` | Not applicable | UTF-8 CSV output | Provides consistent report encoding |
173178

179+
# [PnP PowerShell](#tab/pnpps)
180+
181+
```powershell
182+
183+
# SharePoint online site url
184+
$siteUrl = "https://contoso.sharepoint.com/sites/SPConnect"
185+
186+
# Display name of SharePoint online list
187+
$listName = "My List"
188+
189+
# Connect to SharePoint online site
190+
Connect-PnPOnline -url $siteUrl -Interactive
191+
192+
# Hide SharePoint online list from Site Contents
193+
Set-PnPList -Identity $listName -Hidden $true
194+
195+
# Disconnect SharePoint online connection
196+
Disconnect-PnPOnline
197+
198+
```
199+
200+
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
201+
202+
# [CLI for Microsoft 365](#tab/cli-m365-ps)
203+
204+
```powershell
205+
206+
# SharePoint online site url
207+
$siteUrl = "https://contoso.sharepoint.com/sites/SPConnect"
208+
209+
# Display name of SharePoint online list
210+
$listName = "My List"
211+
212+
# Get Credentials to connect
213+
$m365Status = m365 status
214+
if ($m365Status -match "Logged Out") {
215+
m365 login
216+
}
217+
218+
# Hide SharePoint online list from Site Contents
219+
m365 spo list set --webUrl $siteUrl --title $listName --hidden true
220+
221+
# Disconnect SharePoint online connection
222+
m365 logout
223+
224+
```
225+
226+
[!INCLUDE [More about CLI for Microsoft 365](../../docfx/includes/MORE-CLIM365.md)]
227+
228+
229+
***
230+
231+
232+
174233
## Contributors
175234

176235
|Author(s)|
@@ -189,3 +248,4 @@ The refactoring also introduces explicit configuration variables, execution meta
189248
|2.0|October 03, 2026|Refactored version|
190249

191250
[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
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)