Manage Web Part Permissions using PowerShell


PowerShell script to manage permissions of web parts in Web Part gallery.

# Get Web Object

$web = Get-SPWeb "Web URL"

# Get Web Part Gallery list

# SPListTemplateType.WebPartCatalog Enum value 113

$list = $web.GetCatalog(113)

$listItemCollections = $list.GetItems()

$listItemCollections | ForEach-Object {

$item = $listItemCollections | Where-Object {$_.Name -match "ContentQuery.webpart"}



# Remove existing group permission

$group = $web.SiteGroups["Viewers"]


# Add user permission to the web part item

$account = $web.EnsureUser("domain\user")

$role = $web.RoleDefinitions["Contribute"]

$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)





Comments (0)

Skip to main content