Remove site access requests
As a site owner, delete in bulk all the access requests from a SharePoint site.
Summary
Sometimes, as a site owner you cannot manage all site access requests for your site. Especially when users request access for specific content on the site (Site page, list etc.) you might prefer to grant access to the entire site. Use this script to remove site access requests depending on their status.

$siteUrl = "https://contoso.sharepoint.com/sites/DemoSite"
# Request status: 0 - Pending, 1 - Accepted, 3 - Declined
$requestStatus = 0
Connect-PnPOnline -Url $siteUrl -Interactive
$batch = New-PnPBatch
$accessRequestsList = Get-PnPList | Where-Object {$_.Title -eq "Access Requests"}
$itemsToRemove = Get-PnPListItem -List $accessRequestsList -Query "<View><Query><Where><And><Eq><FieldRef Name='Status'/><Value Type='Number'>$requestStatus</Value></Eq><Eq><FieldRef Name='IsInvitation'/><Value Type='Boolean'>0</Value></Eq></And></Where></Query></View>
"
$itemsToRemove | ForEach-Object {
Remove-PnPListItem -List $accessRequestsList -Identity $_.Id -Batch $batch
}
Invoke-PnPBatch -Batch $batch
Disconnect-PnPOnline
Contributors
| Author(s) |
|---|
| Aimery Thomas |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
Tool documentation & references
- Want to learn more about PnP PowerShell and the cmdlets
Check out the PnP PowerShell site to get started and for the reference to the cmdlets.