This is my first post at stackexchange, so hello everyone. I have issue. I created a script but its doesnt work. I would like to add access to each folder at sharepoint for each group mapped from CSV For example. AADGroup1 should has access to foldername: 76 AADGroup2 should has access to foldername: 173
I have CSV with 15000 groups, that should help me a lot. Thanks !
Install-Module SharePointPnPPowerShellOnline
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin
# Load the SharePoint PnP PowerShell module
Import-Module SharePointPnPPowerShellOnline
# Connect to the SharePoint Online site
$SiteURL = "https://testnantname.sharepoint.com/sites/sitename"
Connect-PnPOnline -Url $SiteURL -UseWebLogin
# Read the data from the CSV file
$CSVFilePath = "C:\Skrypt\departments.csv"
$AccessData = Import-Csv $CSVFilePath
# Loop through each row of the CSV file
foreach ($row in $csvData)
{
$folderName = $row.FolderName
$groupName = $row.GroupName
# Check if the folder exists in the "Documents" library
$folder = Get-PnPFolder -Path "Shared Documents/$folderName" -ErrorAction SilentlyContinue
if ($folder -ne $null)
{
# Add the group to the folder with contribute permissions
$group = Get-PnPGroup -Name $groupName
if ($group -ne $null)
{
Add-PnPFolderPermission -Identity $folder.ServerRelativeUrl -Group $group.Title -AddRole "Contribute"
Write-Host "Permissions added for group $groupName on folder $folderName"
}
else
{
Write-Host "Group $groupName not found"
}
}
else
{
Write-Host "Folder $folderName not found in Shared Documents"
}
}
# Disconnect from the SharePoint Online site
Disconnect-PnPOnline
CSV file example build:
I'm receiving a error about module. But also scipt is not writed properly.
Import-Module : The specified module 'SharePointPnPPowerShellOnline' was not loaded because no valid module file was found in any module directory.
At line:6 char:1
+ Import-Module SharePointPnPPowerShellOnline
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (SharePointPnPPowerShellOnline:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand