Friday, May 6, 2016

Grant permission to group to spList, change inherit -> unique, change other library permissions using POWERSHELL

I understand that you want to grant permission for  the owners group to the Audit Logs library. You can use the script below:
$ownersSPGroupName = "owners"
$webUrl="http://serverURL"
$spweb = Get-SPWeb $webUrl
# Look up the list named "Audit Logs"
$questionsList = $spWeb.Lists["Audit Logs "]
# Set the Read access Item-level permissions settings to "Read items that were created by the user"
$questionsList.ReadSecurity = 2
# Set the Create and Edit access Item-level permissions to "Create items and edit items that were created by the user
$questionsList.WriteSecurity = 2
# Assign the "Contribute" RoleDefition to the site's owners group
$ownersSPGroup = $spWeb.Groups[$ownersSPGroupName]
$questionsList.BreakRoleInheritance($true)
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($ownersSPGroup)
# Assuming this is a default site, we'll look for a role definition of the type "Contributer".
# This way, the script will also work with SharePoint sites created in languages besides English.
$assignment.RoleDefinitionBindings.Add(($spWeb.RoleDefinitions | Where-Object { $_.Type -eq "Contributor" }))
$questionsList.RoleAssignments.Add($assignment)
$questionsList.Update()
$spWeb.Dispose()
$spSite.Dispose()
For more information, please refer to this site: