
Hi @Anonymous
Per my test, you need to connect to sharepoint site instead of admin center. Please refer to following script
#Set Variables
$SiteURL = "https://xxx.sharepoint.com/sites/abc"
$FolderURL = "/TestLibrary9" #Document Library Site Relative URL
#Connect to PnP Online
$UserName="******@xxx.onmicrosoft.com"
$Password = "xxxxxxx"
$SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
$Cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword
#connect to sharepoint online site using powershell
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#Function to reset permissions of all Sub-Folders
Function Reset-SubFolderPermissions($FolderURL)
{
#Get all sub-folders of the Folder - Exclude system folders
$SubFolders = Get-PnPFolderItem -FolderSiteRelativeUrl $FolderURL -ItemType Folder | Where {$_.Name -ne "Forms" -and $_.Name -ne "Document"}
#Loop through each sub-folder
ForEach($SubFolder in $SubFolders)
{
$SubFolderURL = $FolderUrl+"/"+$SubFolder.Name
Write-host -ForegroundColor Green "Processing Folder '$($SubFolder.Name)' at $SubFolderURL"
#Get the Folder Object - with HasUniqueAssignments and ParentList properties
$Folder = Get-PnPFolder -Url $SubFolderURL -Includes ListItemAllFields.HasUniqueRoleAssignments, ListItemAllFields.ParentList, ListItemAllFields.ID
#Get the List Item of the Folder
$FolderItem = $Folder.ListItemAllFields
#Check if the Folder has unique permissions
If($FolderItem.HasUniqueRoleAssignments)
{
#Reset permission inheritance
Set-PnPListItemPermission -List $FolderItem.ParentList -Identity $FolderItem.ID -InheritPermissions
Write-host "`tUnique Permissions are removed from the Folder!"
}
#Call the function recursively
Reset-SubFolderPermissions $SubFolderURL
}
}
#Call the function
Reset-SubFolderPermissions $FolderURL
Here is the test result
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.