Reset Site Collection Permissions

By James|07/03/2012|,

Let's say your site collection permissions are so jacked up you no longer know who has access to what. An easy way to fix this would be to set permissions on the site collection root site, then reset all subsites to inherit permissions. Of course, since that would be easy, Microsoft doesn't provide that functionality via web browser. It is however, fairly simple to accomplish this via PowerShell. The following script will reset permissions on all subsites and lists within a given site collection:

# Set site collection URL
$URL = "your_site_collection"

# Load SharePoint PowerShell snap-in
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

# Retrieve site collection
$sc = Get-SPSite $URL

# Enumerate site collection and reset permissions on all subsites and lists
ForEach ($web in $sc.AllWebs) {
  If ($web.Url -ne $URL) {
    ws = Get-SPWeb $web.Url
    "Resetting subsite inheritance: $($ws.Url)"
    $ws.ResetRoleInheritance()
    $ws.Update()
    $ws.Dispose()
  }
  # Reset list permissions
  $lc = $web.Lists
  ForEach ($list in $lc) {
    "Resetting list inheritance: $($list.Title)"
    $list.ResetRoleInheritance()
    $list.Update()
  }
}

 

Copyright 2011 - 2024 The Lazy IT Admin | All Rights Reserved
menu-circlecross-circle linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram