You can use the below PowerShell script:
$siteUrl = "http://urlToYourSite"
$savePath = "c:\test\BrokenInheritanceReport.csv"
Get-SPSite $siteUrl |
Get-SPWeb -Limit All |
Where { $_.HasUniquePerm -AND $_.ParentWeb -NE $Null } |
Select @{Label="Securable"; Expression={"Web"}},
@{Label="Item"; Expression={$_.ServerRelativeUrl}},
@{Label="Parent"; Expression={$_.ParentWeb.ServerRelativeUrl}} |
Export-CSV $savePath
Get-SPSite $siteUrl |
Get-SPWeb -Limit All |
Select -ExpandProperty Lists |
Where { $_.HasUniqueRoleAssignments -AND -NOT $_.Hidden } |
Select @{Label="Securable"; Expression={"List"}},
@{Label="Item"; Expression={$_.Title}},
@{Label="Parent"; Expression={$_.ParentWebUrl}} |
Export-CSV $savePath -Append
Get-SPSite $siteUrl |
Get-SPWeb -Limit All |
Select -ExpandProperty Lists |
Where { -NOT $_.Hidden -AND $_.EntityTypeName -NE "PublishedFeedList" } |
Select -ExpandProperty Folders |
Where { $_.HasUniqueRoleAssignments } |
Select @{Label="Securable"; Expression={"Folder"}},
@{Label="Item"; Expression={$_.Title}},
@{Label="Parent"; Expression={$_.ParentList.ParentWebUrl + "/" +$_.ParentList.Title}} |
Export-CSV $savePath -Append
Get-SPSite $siteUrl |
Get-SPWeb -Limit All |
Select -ExpandProperty Lists |
Where { -NOT $_.Hidden -AND $_.EntityTypeName -NE "PublishedFeedList" } |
Select -ExpandProperty Items |
Where { $_.HasUniqueRoleAssignments } |
Select @{Label="Securable"; Expression={"Item"}},
@{Label="Item"; Expression={$_.Name}},
@{Label="Parent"; Expression={$_.ParentList.ParentWebUrl + "/" +$_.ParentList.Title}} |
Export-CSV $savePath -Append
Import-CSV $savePath | Sort Parent | Select *
# or open the CSV file in Excel and sort there.
Note:
Source:
SharePoint PowerShell–Find all Broken Inheritance
From the above script - you will get a CSV file for all sites those have been inherited from the parent, now write the below PowerShell code to stop inheritance to those sites:
Stop site inheritance from the CSV report using PowerShell
$sitesCSVPermissionInheriated = Import-CSV "c:\test\SiteInheritanceReport.csv"
Foreach ($oneSite in $sitesCSVPermissionInheriated )
{
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
#Get Site collection and open the web
#$spSite = Get-SPSite "http://servername/sites/TestYogesh"
#$spSiteUrl = Read-Host "Enter the site url"
#$spSite = Get-SPWeb $spSiteUrl
$spSite=Get-SPWeb $oneSite.SiteURL
If ($spsite.IsRootWeb -eq $true)
{
$spWeb = $spSite
Write-Host ($spSite.Url + "This is the Site collection")
# To delete existing permissions presee yes
$yes = Read-Host
"Enter Yes to delete existing permissions on site collections"
if($yes -eq "Yes")
{
# Remove unnecessary groups/users from the site permissions
for ($i = 0; $i -le $spWeb.RoleDefinitions.Count; $i++)
{
$spWeb.RoleDefinitions.Delete($i)
}
}
}
else
{
$spweb = Get-SPWeb $spSiteUrl
If ( ($spWeb.HasUniqueRoleAssignments -and $spWeb.HasUniqueRoleDefinitions) -eq $false )
{
$spWeb.RoleDefinitions.BreakInheritance($true, $true)
#$spWeb.BreakRoleInheritance($true,$true)
$spWeb.Update() Write-Host ($spSite.Url + "Inheritance is Just broken")
# Remove unnecessary groups/users from the site permissions
for ($i = 0; $i -le $spWeb.RoleDefinitions.Count; $i++)
{ $spWeb.RoleDefinitions.Delete($i)
}
} else
{
Write-Host ($spSite.Url + "Inheritance is already broken")
# Remove unnecessary groups/users from the site permissions
for ($i = 0; $i -le $spWeb.RoleDefinitions.Count; $i++)
{
$spWeb.RoleDefinitions.Delete($i)
}
}
}
$spWeb.Dispose()
$spsite.Dispose()
}
Source of the script:
SharePoint 2013: Break Site Permissions Inheritance using PowerShell