How to Remove SharePoint Online Folder Users with PowerShell and CSV
Question details
A global administrator needs to automate the removal of users or groups from SharePoint Online folder permissions using a PowerShell script and a CSV input file.
- Product
- SharePoint Online
- Device & OS
- not provided
- Scenario
- Automating bulk removal of user or group permissions from specific SharePoint folders using PowerShell.
- Observed behavior
- The administrator requires a reliable script or command sequence to process a CSV file and remove permissions efficiently without manual UI intervention.
Ensure you have SharePoint Online Administrator privileges and have the SharePoint Online Management Shell or PnP PowerShell module installed on your computer.
Use PnP PowerShell with a CSV File
Utilize a PowerShell script with PnP cmdlets to read a CSV file, loop through the specified users, and remove their folder permissions systematically.
PowerShell allows administrators to manage large lists of users and groups efficiently. By formatting your data into a CSV file, you can automate repetitive permission removal tasks across multiple folders and sites.
The following steps outline the logic of using a script to read your CSV data and execute the permission removal command.
Create a CSV file named 'users_to_remove.csv' with appropriate column headers such as 'FolderUrl' and 'UserEmail', and populate it with the target data.
Open your PowerShell console and authenticate to your SharePoint environment by running 'Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive'.
Use the Import-Csv cmdlet to read the data into a variable by running '$csvData = Import-Csv -Path "C:\path\to\users_to_remove.csv"'.
Iterate through the CSV rows using a 'foreach' loop. Inside the loop, run the 'Remove-PnPFolderRoleAssignment' or appropriate cmdlet referencing the variables from your CSV to remove the users.
Navigate to the SharePoint UI or run a secondary script to check the folder permissions and confirm the specified users were successfully removed.

Looking for a Lightweight Alternative to Manage Your Documents?
While SharePoint and PowerShell handle complex enterprise administration, WPS Office provides a lightweight, free, and highly compatible alternative for everyday document creation and editing. It is fully compatible with Microsoft Word, Excel, and PowerPoint formats, ensuring seamless transitions without heavy administration overhead.
- 1. Download the Installer: Visit the official WPS website and click the 'Free Download' button.
- 2. Install WPS Office: Run the downloaded installation file and follow the simple on-screen instructions.
- 3. Edit Your Documents: Launch WPS Office to instantly open, edit, and save your existing Microsoft Office files.

Frequently Asked Questions
What modules are required to run SharePoint Online PowerShell scripts?
You will need the SharePoint Online Management Shell or the PnP.PowerShell module installed on your system. You can install PnP PowerShell by running 'Install-Module PnP.PowerShell' in an elevated PowerShell prompt.
Why am I getting an 'Access Denied' error when removing user permissions?
This error typically occurs if your account lacks the necessary Site Collection Administrator privileges for the specific SharePoint site, or if your PowerShell session has not been authenticated properly.
Can I use this method to remove Active Directory groups from SharePoint folders?
Yes, as long as the group's exact name or identifier is correctly listed in your CSV file and the PowerShell script is configured to process group objects, they can be removed just like individual user accounts.
How should I format the CSV file for the PowerShell script?
The CSV file must have clear column headers on the first row (e.g., 'SiteUrl', 'FolderRelativeUrl', 'UserPrincipalName'). Values must be separated by commas, and there should be no trailing spaces in email addresses or URLs.




