Reason
This script checks the history versioning on the lists on a personal OneDrive.
Reason: Onedrive got full of versions of 5 .pst files (each 5 GB, 1TB total), rendering it impossible to access it remotely.
Had to locally delete some files to access it remotely, check versions and deleted them.
The Sharepoint GUI won't allow to set less than 100 versions for a file. Through powershell I found some scripts that blocked the file versioning, however I was not happy with that result. file versioning offers the quick ability to restore to a previous version.
With the code below you can set the amount of versions even below 100.
Please use parts of this script with caution, I am not responsible for any damage.
Script
<#
This script checks the history versioning on the lists on a personal OneDrive.
Reason: Onedrive got full of versions of 5 .pst files (1TB total), rendering it impossible to access it remotely.
Had to locally delete some files to access it remotely, check versions and deleted them.
--var--
$url: asks the url of the personal onedrive page e.g.:"https://rftech2-my.sharepoint.com/personal/rmo_rft_be"
$list: ability to select the list from a table
$log: logfile to track errors
$date: get today's date
$intAnswer: yes/no box
$a: used for the yes/no box shell
$amount: amount of versions needed to save (in GUI minimum is 100)
--HowTo--
1) check if scripts can be run: get-executionpolicy
if needed: set-executionpolicy remotesigned
type Y and press enter
2) Enter the Personal OneDrive url, followed by a O365 admin account
3) first box, click yes to get a list of lists to disable versioning
4) select list
succes: function gets called again and you can restart for another list
failed: script stops
clicked no: continue script
4) second box, click yes to get a list of lists to enable versioning + enter how many versions you need
succes: function gets called again and you can restart for another list
failed: script stops
clicked no: continue script
--EndOfScript
#>
#var
$date = (Get-Date).tostring("yyyyMMdd")
$log = "C:\temp\VersionHistoryScript$date.log"
$a = new-object -comobject wscript.shell
#connect to sharepoint with admin account
$url = read-host "Enter the personal OneDrive url you want to check"
Connect-PnPOnline -url $url
#function to disable the versioning
function DisableVersioning
{
$intAnswer = $a.popup("Do you want to disable versioning history on a list?", 0,"Disable Versioning History",4)
If ($intAnswer -eq 6)
{
$list = (Get-PnPList | Select-Object title,enableversioning,MajorVersionLimit | out-gridview -Title "Please select the List" -OutputMode Single -ErrorAction Stop).title
try
{
Set-PnPList -Identity $list -enableversioning $False
Write-Host "[info]disabled the history versioning" -ForegroundColor Green
"[info]disabled the history versioning for $list" >> $log
Get-PnPList -identity $list | Select-Object title,enableversioning,MajorVersionLimit >> $log
}
Catch
{
Write-Host "[info]Failed to disable history versioning" -ForegroundColor Red
"[info]Failed to disable history versioning for $list" >> $Log
Break
}
DisableVersioning
}
else
{
"[info]Clicked no to disable versioning history" >> $Log
}
}
#function to enable the versioning and set the amount of versions
function EnableVersioning
{
$intAnswer = $a.popup("Do you want to enable versioning history on a list?", 0,"Enable Versioning History",4)
If ($intAnswer -eq 6)
{
$list = (Get-PnPList | Select-Object title,enableversioning,MajorVersionLimit | out-gridview -Title "Please select the List" -OutputMode Single -ErrorAction Stop).title
try
{
$amount= read-host "How many versions do you wish to keep?"
Set-PnPList -identity $list -enableversioning $True -MajorVersions $amount
Write-Host "[info]enabled the history versioning, keeping $amount of versions in my box" -ForegroundColor Green
"[info]enabled the history versioning for $list, keeping $amount of versions" >> $log
Get-PnPList -identity $list | Select-Object title,enableversioning,MajorVersionLimit >> $log
}
Catch
{
Write-Host "[info]Failed to enable history versioning" -ForegroundColor Red
"[info]Failed to enable history versioning for $list" >> $Log
Break
}
EnableVersioning
}
else
{
echo "[info]Clicked no to disable versioning history" >> $Log
}
}
DisableVersioning
EnableVersioning
"Thank you for using my script, report any issue/problem" >> $log
Add comment
Comments