Delete All Versions of a SharePoint File Using PowerShell

There may be instances where you need to remove all previous versions of a file. Well, this is the PowerShell script to do it. This will only work for SharePoint on-premises however.

[string] $UrlToFile

$Site = New-Object -Type Microsoft.SharePoint.SPSite -ArgumentList $UrlToFile
$Web = $Site.OpenWeb()
$SPFile = $Web.GetFile($UrlToFile)

Write-Host “Deleting all versions for file $($UrlToFile)…”

# Remove all versions for file…

# Dispose of the web object

# Dispose of the site object

Save this off as something rememberable, such as Remove-FileVersions.ps1, and pass it the full URL to the file you wish to remove all versions from, for example:

.\Remove-FileVersions.ps1 “”


Office 365, SharePoint Online and SharePoint 2013 On-Premises Feature Matrix

Andrew Connell released an updated Excel Spreadsheet today, which shows the (filterable) differences between Office 365 plans, SharePoint Online, and SharePoint 2013 on-premises. This is a great resource to keep handy, and keep you honest 🙂



<span>%d</span> bloggers like this: