SharePoint: Function to Reset Unique permissions on documents
Function fResetUniquePermissions($SPUrl,$Doclib)
{
try
{
# Open the web and list objects
$web = Get-SPWeb $SPUrl
$list = $web.Lists[$Doclib]
$list.ResetRoleInheritance()
Write-Host "Updated permissions on list."
# Get all items with unique permissions
$itemsWithUniquePermissions = $list.GetItemsWithUniquePermissions()
Write-Host $itemsWithUniquePermissions.Count "number of items with unique permissions found."
# Only update items if some exist
if ($itemsWithUniquePermissions.Count -gt 0) {
foreach ($itemInfo in $itemsWithUniquePermissions) {
$item = $list.GetItemById($itemInfo.Id)
$item.ResetRoleInheritance()
$count++
}
# Display number of items updated
Write-Host "Updated permissions on $count items."
}
else {
Write-Host "No items with unique permissions exist, nothing to update."
}
# Dispose of web object
$web.Dispose()
}
catch [Exception]
{
Write-Host "Exception encountered. Please ensure all arguments are valid." -foregroundcolor Red
Write-Host $_.Exception.Message -foregroundcolor Red
}
}
Related