← script library
Efficiently Manage OneDrive File Permissions with PowerShell
SharePoint & OneDriveDecember 24, 2024
In this post, we will present a PowerShell script that simplifies the management of file permissions within OneDrive for Business. Properly managing file permissions is crucial for collaboration and data security in any organization. This script allows administrators to quickly assign or remove access for users to specific files in OneDrive, ensuring that sensitive information is shared appropriately. Here is the PowerShell script for managing OneDrive file permissions:
powershell
# Connect to SharePoint Online
$tenantAdminUrl = "https://yourtenant-admin.sharepoint.com"
$credential = Get-Credential
Connect-SPOService -Url $tenantAdminUrl -Credential $credential
# Define the OneDrive file and user details
$fileUrl = "https://yourtenant-my.sharepoint.com/personal/username_example_com/Documents/YourFile.docx"
$userEmail = "[email protected]"
$permissionLevel = "Edit" # Options: "View", "Edit"
# Set permissions on the OneDrive file
Set-SPOUser -Site $fileUrl -LoginName $userEmail -IsSiteCollectionAdmin $true
Set-SPOSharingLink -Path $fileUrl -LinkType $permissionLevel -User $userEmail
Write-Host "Permissions have been updated for $userEmail on the file $fileUrl with $permissionLevel access."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-24Streamline File and Folder Permissions Management in SharePoint with PowerShell
2024-12-24Ready when you are.
Try ServerEngine free for 7 days.