← script library

Streamline File and Folder Permissions Management in SharePoint with PowerShell

SharePoint & OneDriveDecember 24, 2024

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:

powershell
# 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.

Ready when you are.

Try ServerEngine free for 7 days.