SharePoint Online: eliminar permisos únicos y restaurar la herencia en una lista usando PowerShell
Requisito: SharePoint Online elimina todos los permisos únicos en una lista o biblioteca de documentos.
¿Cómo eliminar permisos únicos y heredar del padre en SharePoint Online?
Los permisos únicos le brindan un control granular sobre quién puede acceder a qué en SharePoint Online. Sin embargo, en ocasiones puede haber requisitos para restaurar una lista o biblioteca de documentos a sus permisos predeterminados. Eliminar permisos únicos y restaurar la herencia de permisos para una lista o biblioteca permite administrar su seguridad a nivel de sitio en lugar de administrar la seguridad por separado de esa lista. Para restaurar la herencia de permisos para una lista o biblioteca de documentos, haga lo siguiente:
- Inicie sesión en SharePoint Online y navegue hasta la lista o biblioteca donde desea eliminar permisos únicos.
- En la cinta, haga clic en la pestaña Lista/Biblioteca y luego, en el grupo Configuración, haga clic en Lista/Configuración de biblioteca de documentos.
- Haga clic en el enlace "Permisos para esta lista" de la página Configuración de lista en el grupo "Permisos y administración".
En la cinta, haga clic en la pestaña Permisos y luego, en el grupo Herencia, haga clic en Eliminar permisos únicos. Confirme el mensaje con Aceptar.
Esto elimina todos los permisos únicos de la lista y hereda los permisos de su padre. Todos los usuarios con permisos únicos heredarán los permisos del objeto principal, como sitio, biblioteca o carpeta. Veamos SharePoint Online PowerShell para heredar permisos del sitio principal.
Eliminar permisos únicos en una lista o biblioteca de documentos usando PowerShell
Si decide que ya no necesita permisos únicos en una lista o biblioteca de documentos, también puede eliminarlos mediante el script de PowerShell. Aquí está el PowerShell de SharePoint Online para heredar permisos del sitio principal:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Function to remove unique permissions and inherit from the parent
Function Remove-ListUniquePermissions
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ListName
)
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#sharepoint online powershell inherit permissions
$List=$Ctx.Web.Lists.GetByTitle($ListName)
$List.ResetRoleInheritance()
$List.Update()
$Ctx.ExecuteQuery()
Write-Host "Unique Permissions are removed and inherited from the Parent!" -ForegroundColor Green
}
Catch {
write-host -f Red "Error Deleting Unique Permissions!" $_.Exception.Message
}
}
#sharepoint online powershell reset permissions
$SiteURL="https://crescent.sharepoint.com"
$ListName="Projects"
#Call the function to remove unique permissions from a list
Remove-ListUniquePermissions -SiteURL $SiteURL -ListName $ListName
Este PowerShell elimina todos los permisos únicos de una lista determinada y restaura los permisos del sitio.
PowerShell para restablecer la herencia de permisos de todas las listas de una colección de sitios
Para heredar permisos del padre, use este PowerShell. Comprueba si la lista dada tiene permisos únicos y restablece los permisos únicos de la lista heredándolos del sitio principal.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Function to Delete Unique Permission from all lists of a Web
Function Reset-SPOListPermission([Microsoft.SharePoint.Client.Web]$Web)
{
Write-host -f Magenta "Searching Unique Permissions on the Site:"$Web.Url
#Get All Lists of the web
$Lists = $Web.Lists
$Ctx.Load($Lists)
$Ctx.ExecuteQuery()
#Exclude system lists
$ExcludedLists = @("App Packages","appdata","appfiles","Apps in Testing","Cache Profiles","Composed Looks","Content and Structure Reports","Content type publishing error log","Converted Forms",
"Device Channels","Form Templates","fpdatasources","Get started with Apps for Office and SharePoint","List Template Gallery", "Long Running Operation Status","Maintenance Log Library", "Style Library","Master Docs","Master Page Gallery","MicroFeed","NintexFormXml","Quick Deploy Items","Relationships List","Reusable Content","Search Config List", "Solution Gallery", "Site Collection Images","Suggested Content Browser Locations","TaxonomyHiddenList","User Information List","Web Part Gallery","wfpub","wfsvc","Workflow History","Workflow Tasks", "Preservation Hold Library")
#Iterate through each list
ForEach($List in $Lists)
{
#Get the List
$Ctx.Load($List)
$Ctx.ExecuteQuery()
If($ExcludedLists -NotContains $List.Title -and $List.Hidden -eq $false)
{
#Check if the list is using unique permissions
$List.Retrieve("HasUniqueRoleAssignments")
$Ctx.ExecuteQuery()
#Reset broken inheritance of the list
If($List.HasUniqueRoleAssignments)
{
#delete unique permissions of the List
$List.ResetRoleInheritance()
$List.Update()
$Ctx.ExecuteQuery()
Write-host -f Green "`tUnique Permissions Removed from the List: '$($List.Title)'"
}
}
}
#Process each subsite in the site
$Subsites = $Web.Webs
$Ctx.Load($Subsites)
$Ctx.ExecuteQuery()
Foreach ($SubSite in $Subsites)
{
#Call the function Recursively
Reset-SPOListPermission($Subsite)
}
}
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/Retail"
#Get Credentials to connect
$Cred = Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Get the Web
$Web = $Ctx.Web
$Ctx.Load($Web)
$Ctx.ExecuteQuery()
#Call the function to delete unique permission from all lists of a site collection
Reset-SPOListPermission $Web
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
SharePoint Online: eliminar permisos únicos de una lista mediante PnP PowerShell
Aquí está PnP PowerShell para restablecer permisos únicos y heredar permisos del padre en la lista de SharePoint Online. El mismo script también se aplica para eliminar permisos únicos en la biblioteca de documentos de SharePoint Online.
#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/Sales"
$ListName ="Documents"
#Connect PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get the Context
$Context = Get-PnPContext
#Get the list
$List = Get-PnPList -Identity $ListName
#sharepoint online delete unique permissions powershell
$List.ResetRoleInheritance()
$Context.ExecuteQuery()
Esto les dará a todos los usuarios que tengan acceso al sitio principal acceso a la lista o biblioteca. Si desea eliminar permisos únicos en elementos de lista en una lista o biblioteca, use: SharePoint Online: eliminar permisos únicos para todos los elementos de una lista usando PowerShell
