Commands › SharePoint Online

New-SPOSiteFileVersionBatchDeleteJob

SharePoint Online Microsoft.Online.SharePoint.PowerShell New-*

Queues a job to trim versions for all document libraries in a site collection.

Quick start script

# New-SPOSiteFileVersionBatchDeleteJob — quick start (serv365.ai)
# 1. Connect (app-only shown; interactive: omit the certificate parameters)
Connect-SPOService -Url https://$org-admin.sharepoint.com

# 2. Capture the current state first — you cannot roll back what you never recorded
$before = Get-SPOSiteFileVersionBatchDeleteJob
$before | Format-List

# 3. Make the change (dry run first)
New-SPOSiteFileVersionBatchDeleteJob -Identity <SpoSitePipeBind> -MajorVersionLimit <Int32> -MajorWithMinorVersionsLimit <Int32> -WhatIf
New-SPOSiteFileVersionBatchDeleteJob -Identity <SpoSitePipeBind> -MajorVersionLimit <Int32> -MajorWithMinorVersionsLimit <Int32>

# 4. Verify and diff
$after = Get-SPOSiteFileVersionBatchDeleteJob
Compare-Object ($before | Out-String) ($after | Out-String)

Syntax — 3 parameter sets

AutomaticTrim

New-SPOSiteFileVersionBatchDeleteJob [-Identity] <SpoSitePipeBind> [-Automatic] [-WhatIf] [-Confirm]
 [<CommonParameters>]

DeleteOlderThanDays

New-SPOSiteFileVersionBatchDeleteJob [-Identity] <SpoSitePipeBind> [-DeleteBeforeDays <Int32>] [-WhatIf]
 [-Confirm] [<CommonParameters>]

CountLimits

New-SPOSiteFileVersionBatchDeleteJob [-Identity] <SpoSitePipeBind> -MajorVersionLimit <Int32>
 -MajorWithMinorVersionsLimit <Int32> [-WhatIf] [-Confirm] [<CommonParameters>]

Parameters (7)

ParameterTypeRequiredWhat it controls
-Automatic SwitchParameter Trim file versions using automatic version history limit algorithm.
-DeleteBeforeDays Int32 The minimum age of file versions to trim. In other words, all file versions that are older than this number of days will be deleted.
-Identity SpoSitePipeBind yes Specifies the URL of the site collection.
-MajorVersionLimit Int32 yes Trim file version using version count limits. Need to specify `MajorWithMinorVersionsLimit` as well.
-MajorWithMinorVersionsLimit Int32 yes Trim file version using version count limits. Need to specify `MajorVersionLimit` as well.
-Confirm SwitchParameter Prompts you for confirmation before running the cmdlet.
-WhatIf SwitchParameter Shows what would happen if the cmdlet runs. The cmdlet is not run.

Reference facts derived from Microsoft documentation, © Microsoft, licensed CC BY 4.0; restructured with original guidance by serv365.ai.