I am trying to delete all Version History files in SharePoint Online through PowerShell. My research has provided plenty of examples on how to do this in SharePoint 2010 and 2013 but not SharePoint Online. The files reside in Document Libraries. The script below seemed promising for my task but I have been unable to modify it to work for SharePoint Online. What changes would be necessary to make it work for SharePoint Online?
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
# get site
$site = new-object Microsoft.SharePoint.SPSite("http://xxx.sharepoint.com")
# loop through webs
foreach ($web in $site.AllWebs)
{
write-host $web.url
# loop through all lists in web
foreach ($list in $web.Lists)
{
# examine if BaseType of list is NOT a Document Library
if (($list.BaseType -eq "DocumentLibrary") -and ($list.EnableVersioning))
{
# Delete all version history
foreach ($item in $list.Items)
{
# work with the file object as we're in a document library
$file = $item.File
# delete all versions
$file.Versions.DeleteAll()
}
}
}
}
$web.Dispose();
$site.Dispose();