Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions scripts/spo-site-inventory-report/Generate-SPSiteInventory.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<#
.SYNOPSIS
Generates a SharePoint Online site inventory report.

.DESCRIPTION
Connects to a SharePoint Online site using PnP PowerShell and
exports key site information including title, URL, template,
storage usage, lists and document libraries count.

.PARAMETER SiteUrl
URL of the SharePoint Online site.

.PARAMETER OutputFolder
Folder where the CSV report will be generated.

.EXAMPLE
.\Generate-SPSiteInventory.ps1 `
-SiteUrl "https://contoso.sharepoint.com/sites/PMO"

.NOTES
Author: Antonio Villarruel
#>

param(
[Parameter(Mandatory = $true)]
[string]$SiteUrl,

[string]$OutputFolder = "."
)

Write-Host "Connecting to SharePoint site..." -ForegroundColor Cyan

try {
Connect-PnPOnline -Url $SiteUrl -Interactive
}
catch {
Write-Error "Unable to connect to the SharePoint site."
exit
}

Write-Host "Retrieving site information..." -ForegroundColor Cyan

try {

$web = Get-PnPWeb -Includes Title, Url, WebTemplate, Created

$lists = Get-PnPList

$libraries = $lists | Where-Object {
$_.BaseTemplate -eq 101
}

$inventory = [PSCustomObject]@{
SiteTitle = $web.Title
SiteUrl = $web.Url
Template = $web.WebTemplate
CreatedDate = $web.Created
TotalLists = $lists.Count
DocumentLibraries = $libraries.Count
GeneratedDate = Get-Date
}

if (!(Test-Path $OutputFolder)) {
New-Item -ItemType Directory -Path $OutputFolder | Out-Null
}

$outputFile = Join-Path `
$OutputFolder `
"SharePointSiteInventory.csv"

# Export inventory report to CSV
$inventory | Export-Csv `
-Path $outputFile `
-NoTypeInformation `
-Encoding UTF8

Write-Host ""
Write-Host "Inventory generated successfully!" -ForegroundColor Green
Write-Host "File: $outputFile"

}
catch {
Write-Error "Error generating inventory report."
}
111 changes: 111 additions & 0 deletions scripts/spo-site-inventory-report/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Generate SharePoint Site Inventory Report

## Summary

This script generates a SharePoint Online site inventory report using PnP PowerShell.

The report collects key information from a SharePoint site, including:

- Site title
- Site URL
- Site template/type
- Creation date
- Number of lists
- Number of document libraries

The output is exported to a CSV file that can be used for documentation, governance reviews, or SharePoint environment assessments.

![Example Screenshot](assets/example.png)

## Prerequisites

Before running the script:

- Install the latest version of PnP PowerShell:

```powershell
Install-Module PnP.PowerShell -Scope CurrentUser
```

- Access permissions to the SharePoint Online site.

## Usage

Run the script providing the target SharePoint site URL:

```powershell
.\Generate-SPSiteInventory.ps1 `
-SiteUrl "https://contoso.sharepoint.com/sites/PMO"
```

The script generates the following output file:

```
SharePointSiteInventory.csv
```

## Contributors

| Author(s) |
|-----------|
| [Antonio Villarruel](https://github.com/a-villarruel) |

[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]

<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-site-inventory-report"
aria-hidden="true" /># Generate SharePoint Site Inventory Report

## Summary

This script generates a SharePoint Online site inventory report using PnP PowerShell.

The report collects key information from a SharePoint site, including:

- Site title
- Site URL
- Site template/type
- Creation date
- Number of lists
- Number of document libraries

The output is exported to a CSV file that can be used for documentation, governance reviews, or SharePoint environment assessments.

![Example Screenshot](assets/example.png)

## Prerequisites

Before running the script:

- Install the latest version of PnP PowerShell:

```powershell
Install-Module PnP.PowerShell -Scope CurrentUser
```

- Access permissions to the SharePoint Online site.

## Usage

Run the script providing the target SharePoint site URL:

```powershell
.\Generate-SPSiteInventory.ps1 `
-SiteUrl "https://contoso.sharepoint.com/sites/PMO"
```

The script generates the following output file:

```
SharePointSiteInventory.csv
```

## Contributors

| Author(s) |
|-----------|
| [Antonio Villarruel](https://github.com/a-villarruel) |

[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]

<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-site-inventory-report"
aria-hidden="true" />
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions scripts/spo-site-inventory-report/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[
{
"name": "spo-site-inventory-report",
"source": "pnp",
"title": "Generate SharePoint Site Inventory Report",
"shortDescription": "Generate an inventory report for a SharePoint site including lists, libraries, pages and storage information",
"url": "https://pnp.github.io/script-samples/spo-site-inventory-report/README.html",
"longDescription": [
""
],
"creationDateTime": "2026-07-24",
"updateDateTime": "2026-07-24",
"products": [
"SharePoint",
"Office",
"Graph",
"PowerApps",
"Teams",
"Power Automate",
"Microsoft Todo",
"Azure",
"Microsoft 365 Copilot"
],
"metadata": [
{
"key": "PNP-POWERSHELL",
"value": "1.11.0"
}
],
"categories": [
"Modernize",
"Data",
"Deploy",
"Provision",
"Configure",
"Report",
"Security",
"AI",
"Microsoft 365 Copilot"
],
"tags": [
"<Cmdlets-Used>"
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-site-inventory-report/assets/preview.png",
"alt": "Preview of the sample Generate SharePoint Site Inventory Report"
}
],
"authors": [
{
"gitHubAccount": "a-villarruel",
"company": "",
"pictureUrl": "https://github.com/a-villarruel.png",
"name": "Antonio Villarruel"
}
],
"references": [
{
"name": "Want to learn more about PnP PowerShell and the cmdlets",
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
"url": "https://aka.ms/pnp/powershell"
}
]
}
]