Introduction
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
Prerequisites
- 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 |
[email protected] |
/personal/veera_kaveri_sample_com/Documents/New Joinees Tasks |
Read |
https://sample-my.sharepoint.com/personal/veera_kaveri_sample_com |
[email protected] |
/personal/veera_kaveri_sample_com/Documents/BoxUpdate |
Contribute |
https://sample-my.sharepoint.com/personal/veera_kaveri_sample_com |
[email protected] |
/personal/veera_kaveri_sample_com/Documents/Resumes |
Full Control |
https://sample-my.sharepoint.com/personal/veera_kaveri_sample_com |
Process
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.
- #Variables
- $CSVPath = "D:\Bharat\ODFB\OnedriveUsers2.csv"
- $ListName = "Documents"
- $username = "[email protected]"
- $password = '#########'
- $cred = New - Object - TypeName System.Management.Automation.PSCredential - argumentlist $userName, $(convertto - securestring $Password - asplaintext - force)
- #Get data from CSV
- $CSVData = Import - Csv $CSVPath
- #Iterate through each row in CSV
- ForEach($Row in $CSVData) {
- Try {
- #Connect to SharePoint Online Site
- Write - host "Connecting to Site: "
- $Row.SiteURL
- Connect - PnPOnline - Url $Row.SiteURL - Credentials $cred
- Set - PnPFolderPermission - List $ListName - Identity $Row.Folder - User $Row.UserEmail - AddRole $Row.Role
- DisConnect - PnPOnline
- }
- Catch {
- write - host - f Red "Error Adding User to Group:"
- $_.Exception.Message
- DisConnect - PnPOnline
- }
- }
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.
Conclusion
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.