diff --git a/scripts/spo-site-inventory-report/Generate-SPSiteInventory.ps1 b/scripts/spo-site-inventory-report/Generate-SPSiteInventory.ps1 new file mode 100644 index 000000000..ee402166d --- /dev/null +++ b/scripts/spo-site-inventory-report/Generate-SPSiteInventory.ps1 @@ -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." +} \ No newline at end of file diff --git a/scripts/spo-site-inventory-report/README.md b/scripts/spo-site-inventory-report/README.md new file mode 100644 index 000000000..96aba8f2f --- /dev/null +++ b/scripts/spo-site-inventory-report/README.md @@ -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)] + +# 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)] + + \ No newline at end of file diff --git a/scripts/spo-site-inventory-report/assets/example.png b/scripts/spo-site-inventory-report/assets/example.png new file mode 100644 index 000000000..f69900eb3 Binary files /dev/null and b/scripts/spo-site-inventory-report/assets/example.png differ diff --git a/scripts/spo-site-inventory-report/assets/preview.png b/scripts/spo-site-inventory-report/assets/preview.png new file mode 100644 index 000000000..72a9255df Binary files /dev/null and b/scripts/spo-site-inventory-report/assets/preview.png differ diff --git a/scripts/spo-site-inventory-report/assets/sample.json b/scripts/spo-site-inventory-report/assets/sample.json new file mode 100644 index 000000000..5dc96a44d --- /dev/null +++ b/scripts/spo-site-inventory-report/assets/sample.json @@ -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": [ + "" + ], + "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" + } + ] + } +]