30 April 2022

Remove OneDrive file previous versions

  1. Install PnP PowerShell:

    Install-Module -Name "PnP.PowerShell"

  2. Connect to the OneDrive URL:

    Connect-PnPOnline -Url https://company-my.sharepoint.com/personal/jsmith_company_com -Interactive

  3. List the file versions:

    Get-PnPFileVersion -Url "Documents/Documents/myfile.txt"

  4. Remove all the file versions (does not remove file itself):

    Remove-PnPFileVersion -Url "Documents/Documents/myfile.txt" -All

Using PnP PowerShell, you can also get the size of a folder (in MB):

$Folder = Get-PnPFolder -Url "Documents/Documents" -Includes ListItemAllFields Write-host "Size of the Folder:" $([Math]::Round(($Folder.ListItemAllFields.FieldValues.SMTotalSize.LookupId/1MB),2))

No comments:

Post a Comment