Commands › SharePoint Online

New-SPOListFileVersionBatchDeleteJob

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

Queues a job to trim versions from a document library.

Quick start script

# New-SPOListFileVersionBatchDeleteJob — 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-SPOListFileVersionBatchDeleteJob
$before | Format-List

# 3. Make the change (dry run first)
New-SPOListFileVersionBatchDeleteJob -List <SPOListPipeBind> -MajorVersionLimit <Int32> -MajorWithMinorVersionsLimit <Int32> -WhatIf
New-SPOListFileVersionBatchDeleteJob -List <SPOListPipeBind> -MajorVersionLimit <Int32> -MajorWithMinorVersionsLimit <Int32>

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

Syntax — 4 parameter sets

AutomaticTrim

New-SPOListFileVersionBatchDeleteJob [-Site] <SpoSitePipeBind> -List <SPOListPipeBind> [-Automatic] [-WhatIf]
 [-Confirm] [<CommonParameters>]

DeleteOlderThanDays

New-SPOListFileVersionBatchDeleteJob [-Site] <SpoSitePipeBind> -List <SPOListPipeBind>
 [-DeleteBeforeDays <Int32>] [-WhatIf] [-Confirm] [<CommonParameters>]

CountLimits

New-SPOListFileVersionBatchDeleteJob [-Site] <SpoSitePipeBind> -List <SPOListPipeBind>
 -MajorVersionLimit <Int32> -MajorWithMinorVersionsLimit <Int32> [-WhatIf] [-Confirm] [<CommonParameters>]

ByPolicy

New-SPOListFileVersionBatchDeleteJob [-Site] <SpoSitePipeBind> -List <SPOListPipeBind> [-FileTypes <String[]>]
 [-ExcludeDefaultPolicy] [-TrimUseListPolicy] [-WhatIf] [-Confirm] [<CommonParameters>]

Parameters (11)

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.
-ExcludeDefaultPolicy SwitchParameter Indicates whether to trim versions based on the default version history limits.
-FileTypes String[] An array of file type names to trim versions. The supported file type names are: - Audio - OutlookPST - Video
-List SPOListPipeBind yes The document library name or Id.
-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.
-Site SpoSitePipeBind yes Specifies the URL of the site.
-Confirm SwitchParameter Prompts you for confirmation before running the cmdlet.
-TrimUseListPolicy SwitchParameter Indicates whether to trim versions by applying the document library's version history limits.
-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.