PowerShell Script to Reset Permissions on all Documents in a Document Library in SharePoint Online.

Here's a PowerShell script that resets permissions on all documents in a SharePoint Online document library:

#Connect to SharePoint Online Site
$SiteURL = "https://yourdomain.sharepoint.com/sites/sitename"
$UserName = "yourusername@yourdomain.com"
$Password = "yourpassword"
$SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential($UserName, $SecurePassword)

Connect-PnPOnline -Url $SiteURL -Credentials $Cred

#Set Variables
$ListName = "Documents"
$FolderPath = "/Shared Documents"

#Get all Documents from the document library
$Documents = Get-PnPListItem -List $ListName -Folder $FolderPath

#Loop through each document and reset permissions
foreach ($Doc in $Documents)
{
    Set-PnPListItemPermission -List $ListName -Identity $Doc.Id -InheritPermissions $true -ClearAllPermissions $true
}

Write-Host "Permissions reset complete."

You will need to replace the following placeholders with the appropriate values:

  • https://yourdomain.sharepoint.com/sites/sitename - the URL of your SharePoint Online site
  • yourusername@yourdomain.com - your username for the SharePoint Online site
  • yourpassword - your password for the SharePoint Online site
  • Documents - the name of your document library
  • /Shared Documents - the path to the folder containing the documents that you want to reset permissions for

Once you have updated the placeholders with the appropriate values, save the script as a .ps1 file and run it in PowerShell. The script will loop through each document in the specified folder and reset the permissions to inherit from the parent folder.

Comments

Popular posts from this blog

Unveiling the Power of PowerShell Regions: A Comprehensive Guide

PowerShell Script to Remotely Update Firmware on Brother Printers Microsoft