Skip to content

Add SPO file version report and trim script for Teams sites#962

Open
fabianhutzli wants to merge 1 commit into
pnp:mainfrom
fabianhutzli:report-trim-file-versions
Open

Add SPO file version report and trim script for Teams sites#962
fabianhutzli wants to merge 1 commit into
pnp:mainfrom
fabianhutzli:report-trim-file-versions

Conversation

@fabianhutzli

Copy link
Copy Markdown
Contributor

Summary

Adds a block-based PnP PowerShell script to audit and clean up file version history across Microsoft Teams sites and their associated private channels. The script is structured for operational use in large environments: each block is executed sequentially and independently, with an optional batching mechanism for high site counts.

The script was born from a real-world need to reclaim SharePoint storage at scale while preserving control — operators can inspect projected savings before committing to any deletion.

Features

  • Group-based site discovery — resolves all Teams sites (default + private channels) from a list of M365 group names, collecting owners, document libraries, storage usage, and current auto-expiration policy
  • Per-site version expiry report — creates a hidden StorageReport library on each site and triggers New-PnPSiteFileVersionExpirationReportJob to generate a CSV of all file versions eligible for deletion
  • Storage savings calculation — aggregates downloaded CSVs to show total reclaimable storage before any data is removed
  • Batch delete with automatic versioning — triggers New-PnPSiteFileVersionBatchDeleteJob -Automatic and enforces automatic versioning policy via Set-PnPSiteVersionPolicy
  • Safe-by-default execution — a $reportMode flag (defaulting to $true) prevents jobs from starting until explicitly set to $false
  • Batch processing support$result can be split into named batch variables for incremental processing across large site inventories

Script type

PnP PowerShell

Author

Fabian Hutzli

Introduces a block-based PnP PowerShell script to audit and clean up
file version history across Microsoft Teams sites (including private
channels). The script generates per-site version expiry reports,
calculates storage savings, and triggers batch delete jobs with
automatic versioning policy enforcement.

Includes sample.json metadata with cmdlet tags and a detailed README
covering the sequential block execution model and user context
requirements for the version report and trim jobs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant