← script library
Streamline SharePoint File Permissions Management with PowerShell
SharePoint & OneDriveJanuary 4, 2025
Managing file and folder permissions in SharePoint can often be complex and time-consuming. Using PowerShell, you can automate this process, making it easier to handle permissions on SharePoint document libraries and lists. This PowerShell script will help you grant specific permissions to a SharePoint group for a given document library.
powershell
# Install the SharePoint Online Management Shell if not already installed
Install-Module -Name "Microsoft.Online.SharePoint.PowerShell" -Force
# Connect to SharePoint Online
$siteUrl = "https://yourtenant.sharepoint.com/sites/yoursite"
Connect-SPOService -Url $siteUrl
# Specify the group and document library
$groupName = "Your SharePoint Group" # Replace with your group name
$documentLibrary = "Documents" # Replace with your document library name
# Get the group
$group = Get-SPOSiteGroup -Site $siteUrl -Group $groupName
# Check if permissions are already set
$roleAssignments = Get-SPOSiteGroup -Site $siteUrl -Group $groupName
# Granting permissions to the document library
$roleDef = "Contribute" # Example: Contribute permission
Set-SPOSiteGroup -Site $siteUrl -Group $groupName -AddRoleAssignment $roleDef -List $documentLibraryRun it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in SharePoint & OneDrive
Monitor SharePoint Site Usage with PowerShell
2025-01-04Managing File Permissions in SharePoint with PowerShell
2025-01-04Automate User Permissions Management in SharePoint with PowerShell
2024-12-24Efficiently List User Permissions in SharePoint with PowerShell
2024-12-24Efficiently Manage OneDrive File Permissions with PowerShell
2024-12-24Streamline File and Folder Permissions Management in SharePoint with PowerShell
2024-12-24Ready when you are.
Try ServerEngine free for 7 days.