Hi @john john ,
You also need to remove this user from all files and folders with the help of PnP PowerShell:
#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/sites/Marketing"
$ListName="Branding"
$UserAccount = "i:0#.f|membership|******@Crescent.com"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the User
$User = Get-PnPUser -Identity $UserAccount -ErrorAction Stop
#Get all list items
$ListItems = Get-PnPListItem -List $ListName -PageSize 500 -Fields ID
$ItemCount = $ListItems.Count
#Iterate through each list item
$Counter=1
ForEach($ListItem in $ListItems)
{
#Display a progress bar
Write-Progress -PercentComplete ($Counter / $ItemCount * 100) -Activity "Processing Items from List:" -Status "Checking Item '$($ListItem.FieldValues.FileRef)' ($Counter of $ItemCount)"
#Check if the Item has unique permissions
$HasUniquePermissions = Get-PnPProperty -ClientObject $ListItem -Property "HasUniqueRoleAssignments"
If($HasUniquePermissions)
{
#Get Permissions Assigned to the Item
$RoleAssignments = Get-PnPProperty -ClientObject $ListItem -Property RoleAssignments
#Remove user from Item permissions - If Found!
[Bool]$UserFound = $false
ForEach($RoleAssignment in $RoleAssignments)
{
$Member = Get-PnPProperty -ClientObject $RoleAssignment -Property Member
If($Member.LoginName -eq $User.LoginName)
{
$UserFound = $True
$ListItem.RoleAssignments.GetByPrincipal($User).DeleteObject()
Invoke-PnPQuery
}
}
If($UserFound) { Write-host -f Green "Removed user from $($Listitem.FileSystemObjectType) at '$($ListItem.FieldValues.FileRef)' Permissions!" }
}
$Counter++
}
}
Catch {
write-host -f Red "Error Removing user from List Items:" $_.Exception.Message
}
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.