Smart OneDrive For Business Folder Collaboration With Other ODFB Users


Hi guys, let's try to explore a smart process of ODFB specific folders collaboration/permission granting to another ODFB User Account within the same tenant something better than my previous blog.
The possible permission types are:
  • Read
  • Contribute
  • Full Control
  • All the Source and Target User Accounts must be ODFB provisioned along with a minimum Microsoft E3-E5 license
  • Windows PowerShell ISE with all PnP packages, modules to be installed
  • Service Account of the Tenant Account to run the PnP script seamlessly
CSV report with all the columns:
UserEmail Folder Role SiteURL /personal/veera_kaveri_sample_com/Documents/New Joinees Tasks Read /personal/veera_kaveri_sample_com/Documents/BoxUpdate Contribute /personal/veera_kaveri_sample_com/Documents/Resumes Full Control
Use the below PnP script after configuring the below-highlighted areas and run it to have the above permission roles assigned to the above folder specific ODFB User Accounts.
  1. #Variables  
  2. $CSVPath = "D:\Bharat\ODFB\OnedriveUsers2.csv"  
  3. $ListName = "Documents"  
  4. $username = ""  
  5. $password = '#########'  
  6. $cred = New - Object - TypeName System.Management.Automation.PSCredential - argumentlist $userName, $(convertto - securestring $Password - asplaintext - force)  
  7. #Get data from CSV  
  8. $CSVData = Import - Csv $CSVPath  
  9. #Iterate through each row in CSV  
  10. ForEach($Row in $CSVData) {  
  11.     Try {  
  12.         #Connect to SharePoint Online Site  
  13.         Write - host "Connecting to Site: "  
  14.         $Row.SiteURL  
  15.         Connect - PnPOnline - Url $Row.SiteURL - Credentials $cred  
  16.         Set - PnPFolderPermission - List $ListName - Identity $Row.Folder - User $Row.UserEmail - AddRole $Row.Role  
  17.         DisConnect - PnPOnline  
  18.     }  
  19.     Catch {  
  20.         write - host - f Red "Error Adding User to Group:"  
  21.         $_.Exception.Message  
  22.         DisConnect - PnPOnline  
  23.     }  
  24. }  
Smart One Drive For Business Folder Collaboration To Other ODFB Users
The above script is run automatically, as we are hard coding the Admin Login details as shown in the above PnP Script and all the above-mentioned specific folders from their respective ODFB account get permission shared with the Role type mentioned to the User Email mentioned in the CSV rows.


The entire process above can be used for bulk user accounts permissions/collaborations to various ODFB Folders via PnP scripting by just passing the CSV report prepared in the above format and also promotes seamless running without giving login details during the runtime.