Streamline File and Folder Permissions Management in SharePoint with PowerShell
In this post, we will provide a PowerShell script to help manage file and folder permissions in SharePoint. Proper management of permissions is essential for ensuring that users have the appropriate access while maintaining security. This script allows administrators to quickly grant or revoke permissions for specific users on SharePoint document libraries, making it easier to maintain control over sensitive information. Here is the PowerShell script for managing SharePoint permissions:
# Connect to SharePoint Online
$siteUrl = "https://yourtenant.sharepoint.com/sites/YourSite"
$credential = Get-Credential
Connect-PnPOnline -Url $siteUrl -Credentials $credential
# Define the file or folder URL and the user to manage permissions
$itemUrl = "/sites/YourSite/Shared Documents/YourFile.txt"
$userEmail = "[email protected]"
$role = "Edit" # Options: "View", "Edit"
# Grant permissions to the user
Set-PnPListItemPermission -List "Shared Documents" -Identity $itemUrl -User $userEmail -AddRole $role
Write-Host "Permissions have been granted to $userEmail for the file at $itemUrl with the role $role."Run 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-04Streamline SharePoint File Permissions Management 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-24Ready when you are.
Try ServerEngine free for 7 days.