Add-PSSnapin Microsoft.SharePoint.Powershell
$url = "http://weburl"
$listName = "List Name"
$permissionLevel = "Permission Level Name"
$groupName = "Enter Group Name"
#Grant permission on all uniquely secured list items to the specified group
$web = Get-SPWeb $url; $list = $web.Lists[$listName]
$permission = $web.RoleDefinitions[$permissionLevel]
$principal = $web.SiteGroups[$groupName]
#Process each list item
foreach ($item in $list.Items) {
Write-Output ("Item #" + $item.ID.ToString())
#Check to see whether the item is uniquely secured
if ($item.HasUniqueRoleAssignments -eq $FALSE) {
Write-Output " No change, permissions are inherited."
}
else
{
#Find an existing role assignment for this principal
$assignments = $item.RoleAssignments
$assignment = $assignments | where {$_.Member.Name -eq $principal.Name}
if ($assignment -eq $NULL) {
#Add a new role assignment for the principal
$assignment = new-object Microsoft.SharePoint.SPRoleAssignment($principal)
$assignment.RoleDefinitionBindings.Add($permission)
$assignments.Add($assignment)
Write-Output (" Granted " + $permissionLevel + " to " + $groupName)
}
elseif ($assignment.RoleDefinitionBindings.Contains($permission) -ne $TRUE)
{
#Update the principal's role assignment to add the desired permission level
$assignment.RoleDefinitionBindings.Add($permission)
$assignment.Update()
Write-Output (" Updated " + $groupName + " permissions to " + $permissionLevel)
}
else
{
Write-Output " No change."
}
}
}
$web.Dispose()
Read Next
Migrate data from Source to Destination Library without changing the audit trail column values– PowerShell
Importing Best Bets as Query Rule in SharePoint 2013 using PowerShell
Tags
AAD
AI
API
ARM
ASPM
AWS
AWS Comprehend
AWS Secrets Manager
Actions
Amazon Bedrock
Angular
Ansible
Automation
Azure
Azure CLI
BDC
Bash
Bible API
Bitbucket
Bot
CI/CD
CLI for Microsoft 365
CSOM
Citrix
Cloud
Cloud Computing
Cloud Watch
CloudWatch
CodeWhisperer
Computer Vision API
Copilot
Data Extraction
DefectDojo
DevOps
DevSecOps
Docker
Docker Scout
Dotnet
EKS
Elastic Transcoder
EventBridge
External Secrets Operator
Faith
GCP
GenAI
Generative AI
GitHub
GitLab
GitLeaks
GitOps
Google Analytics
Governance
Graph API
Groups
HIBP API
Hashicorp
IAM
IaC
Identity
InfoPath
Integration
Istio
JQuery
JavaScript
Jenkins
Jinja2
Kiali
Kubernetes
LUIS
Lambda
LangChain
Linode
Linux
Lotus Notes
Machine Learning
Manage Secrets
Microservices
Microsoft 365
Microsoft Power Platform
Microsoft Teams
Migration
Milvus
NJSScan
Nintex
OIDC
Office Store
Ollama
OpenAI
Performance Optimization
Permissions
Pinecone
PnP
Pod
Postman
Power Apps
Power Automate
PowerApps
PowerShell
Python
REST
Redis
Roles
S3
SNS
SPFX
SQL Server
SSL
SSRS
Security
Semantic Search
Semgrep
Serverless
Service Mesh
ServiceNow
SharePoint
Slack
TFS
Teams
Terraform
VM
Vault
Vector Database
Vulnerability
Windows
Windows Server
YAML
Yammer
tfsec