Switch OneDrive for Business Accounts to Intelligent Versioning
Bringing Intelligent Automatic Versioning to OneDrive for Business
In October, I reported about the deployment of intelligent versioning for SharePoint Online and noted that I thought this is a significant advance for storage management. Some of the gloss is taken off by the clash between retention processing and intelligent versioning. The former wants to keep versions while the latter seeks to remove unwanted versions. Still, anything that seeks to relieve the pressure on expensive SharePoint Online storage is appreciated, and I think intelligent versioning is the way forward.
OneDrive for Business Storage
Because Microsoft makes generous amounts of storage quota available for OneDrive for Business users, less pressure arises through the cost of storage. Microsoft has dedicated a lot of effort to move the files generated by apps such as Loop (components), Whiteboard, and Stream to OneDrive for Business with the idea being that OneDrive is your personal storage space. Sometimes too much gets stored in OneDrive, such as the selection of OneDrive by PowerShell as the default location to install new modules, but overall, it’s a good thing to have a common default storage location for personal files.
Enabling Intelligent Versioning Manually
Which brings us to the question of whether it’s possible to enable automatic versioning for OneDrive for Business. The answer is yes. You can enable intelligent versioning manually or with PowerShell.
To enable an account manually:
- Sign into the account and access site settings through the cogwheel icon.
- Select OneDrive Settings.
- Click More Settings and then choose the link to Return to the Old Site settings page.
- Select Site Libraries and Lists.
- Click on the link to the default document library. In English, the link is Documents.
- Choose Versioning settings.
- Select Automatic versioning (Figure 1) and click OK.
Enabling Intelligent Versioning with PowerShell
Enabling an important feature manually is boring when it needs to be done for many OneDrive for Business accounts. PowerShell is the go-to tool for automating Microsoft 365 administrative operations, so that’s the next step. Despite explaining how to use the SharePoint Online management module to enable intelligent versioning for SharePoint Online sites in my article, I began by investigating if it is possible to do the job with the PnP module. One good reason for selecting PnP is because this module offers more access to SharePoint settings than any other route.
I started by connecting to a OneDrive for Business account by using the Get-MgUserDrive cmdlet to find the OneDrive account for a user account, trimming the OneDrive URL to the form required by PnP, and connecting. If you’re not a regular user of PnP, a recent change in the multitenant app used by the module means that interactive connections are handled differently. After connecting, I was able to run Get-PnPList to retrieve the settings of the document library:
$User = Get-MgUser -UserId Tony.Redmond@office365itpros.com $OneDrive = Get-MgUserDrive -userid $User.Id | Select-Object {$_.Name -like "*OneDrive*"} $SiteUrl = $Drive.WebUrl.Substring(0, $Drive.WebUrl.IndexOf("/Documents")+1) Connect-PnPOnline $SiteURL -Interactive -ClientId cb5f363f-fbc0-46cb-bcfd-0933584a8c57 $LibrarySettings = Get-PnPList -Identity 'Documents'
Alas, the settings don’t include anything to enable intelligent versioning, so this experiment came to a crashing halt.
Next, I fell back on a combination of the Microsoft Graph PowerShell SDK and the SharePoint Online management module to:
- Find the set of user accounts licensed to use SharePoint Online.
- For each account, find if they have a OneDrive for Business account. The Get-SPOSite cmdlet can fetch details of either a SharePoint Online site or OneDrive for Business account.
- If an account exists, check if intelligent versioning is enabled and if not, enable it.
- Capture and report the results.
This approach worked and all the OneDrive for Business accounts in my tenant are now enabled for intelligent versioning (Figure 2). You can download the script from GitHub.
Keep PowerShell Modules Updated
After going down the rabbit hole of PnP, it was nice to find a solution with the Graph SDK and SharePoint Online PowerShell. This is no criticism of PnP. New builds of that module appear frequently, and the maintainers do an excellent job to track change within SharePoint Online and respond with cmdlet updates. Perhaps the change to deal with enabling intelligent versioning is in one of their nightly updates.
It is important to update modules on an ongoing basis. I used V2.25 of the SDK, version 16.0.25409.12000 of the SharePoint Online management module, and version 2.2.0 of the PnP.PowerShell module. Use the script described in this article to update your modules (and clear out old versions of modules).
Need more help to write PowerShell for Microsoft 365? Get a copy of the Automating Microsoft 365 with PowerShell eBook, available standalone or as part of the Office 365 for IT Pros eBook bundle.