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"
            Write-Host "Group $groupName not found"
        Write-Host "Folder $folderName not found in Shared Documents"

# Disconnect from the SharePoint Online site

CSV file example build:

enter image description here

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

1 Answer 1


Try adding the -Name parameter to the first line of your script:

Install-Module -Name SharePointPnPPowerShellOnline

Additionally, you might benefit from using the newer PnP.PowerShell rather than the legacy SharePointPnPPowerShellOnline

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.