How to Remove User Permissions in SharePoint 2013/2016 using Powershell

Hi  Sharepointers,

Lets assume the scenario when a new user leaves the organisation and you want to remove the permission from the sharepoint site that he has acesss to .  You need to run the below powershell to remove the permissions as a adminstrator from powershell commands.

$sites = Get-SPSite -Limit All

#This loops through each site collection and calls it ‘siteCollection’
foreach ($siteCollection in $sites)
{
# all the webs in the site collection
$webs = $siteCollection.AllWebs

#all the webs
foreach ($website in $webs)
{
$user = get-spuser -Identity Domain\UserAccount -Web $website.url
#gets all the lists in the library
$lists = $web.Lists
foreach ($list in $lists)
{
$list.RoleAssignments.Remove( $user)
}
}
}

Happy Sharepointing 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *