how to stop group permission from folders using powershell in sharepoint online

Raki 481 Reputation points


i have list of folders in a library and i want to stop sharing for a specific group for those folders. i could stop sharing manually one by one but its not feasible. so i just want to remove/stop group from folders not from the library level. Again group shouldn't be deleted from library by stopping sharing at folder level.

Thanks in Advance!

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
8,030 questions
0 comments No comments
{count} votes

Accepted answer
  1. JoyZ 18,001 Reputation points

    Hi @Raki ,

    Please create a csv file contains one column with header "URL" , which are folders url you want to remove permissions, then use pnp powershell to remove permissions on these folders for specific SharePoint group.

    Please refer to the following article(remember to change the user to SharePoint group):

    PnP PowerShell to Remove User from Folder Permissions from a CSV file


    Simple test for your reference:

    Here are my document library floders which I want to remove specific group permissions on them:


    This is the csv file called Folders.csv stored in C:\Temp:


    Then run following pnp powershell to remove specific SharePoint group permissions on these folders, please remember to change the SharePoint group name for yourself, in my test is "TestGroup":

    $CSVFile = "C:\Temp\Folders.csv"  
    Try {  
        #Connect to PnP Online  
        Connect-PnPOnline -Url -Credentials (Get-Credential)  
        #Get content from CSV file  
        Import-Csv $CSVFile | ForEach-Object {  
            Write-host "Processing Folder:"$_.URL  
            #Get the Folder from URL  
            $Folder = Get-PnPFolder -Url $_.URL  
            #Get Folder Item  
            $FolderItem = Get-PnPProperty -ClientObject $Folder -Property ListItemAllFields  
            $HasUniquePerm =  Get-PnPProperty -ClientObject $FolderItem -Property HasUniqueRoleAssignments  
            #Break Permission Inheritance  
                $FolderItem.BreakRoleInheritance($True, $True)  
                Write-host "`tFolder's Permission Inheritance Broken!"  
            #Get the User  
            $User = Get-PnPGroup -Identity 'TestGroup' -ErrorAction Stop  
            #Get Permissions from the Folder  
            $RoleAssignments = Get-PnPProperty -ClientObject $FolderItem -Property RoleAssignments  
            #Remove user from folder permissions  
            [Bool]$UserFound = $false  
            ForEach($RoleAssignment in $RoleAssignments)  
               $Member =  Get-PnPProperty -ClientObject $RoleAssignment -Property Member  
               If($Member.LoginName -eq $User.LoginName)  
                    $UserFound = $True  
            If($UserFound) { Write-host "`tRemoved user from Folder Permission!" }   
    Catch {  
        write-host -f Red "Error Removing user from Folder:" $_.Exception.Message  

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.

    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Raki 481 Reputation points

    Thanks for your reply. how to get the list of folders urls?