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
-----------------------------------------------Update-----------------------------------------------
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 https://hasai.sharepoint.com/sites/Julie -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
If(!$HasUniquePerm)
{
$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
$FolderItem.RoleAssignments.GetByPrincipal($User).DeleteObject()
Invoke-PnPQuery
}
}
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.