Having authenticated to a SharePoint online Site, Site Collection or a OneDrive site, like me, you may have the need to add retention labels to folders and the files within those folders. I have seen this done a lot using the SharePoint Online PowerShell Module but in terms of authentication in the modern world it is not so easy to authenticate to that module at site level.
So in steps the mega powerful PnP PowerShell. The method I will demonstrate below will use PnP to apply the retention label to both root Documents & Shared Documents and an alternative way to apply the labels to subfolders too.
Should you be looking to automate this process in bulk or are just looking for an easy way to authenticate without having to respond to MFA prompts. Please see Connect-PnPOnline Unattended Using Azure App-Only Tokens.
Set Retention Label on the Root Folder
$RootLabel = "Default" # SharePoint Online Set-PnPLabel -List "Shared Documents" -Label $RootLabel # OneDrive for Business Set-PnPLabel -List "Documents" -Label $RootLabel