Skip to content

Commit

Permalink
Merge pull request #704 from a1mery/spo-remove-access-requests
Browse files Browse the repository at this point in the history
New script sample to remove site access requests
  • Loading branch information
pkbullock authored Jul 2, 2024
2 parents 88bb045 + 36f3c12 commit 920f45a
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
50 changes: 50 additions & 0 deletions scripts/spo-remove-access-requests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
plugin: add-to-gallery
---

# Remove site access requests

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

![Example Screenshot](assets/example.png)


# [PnP PowerShell](#tab/pnpps)

```powershell
$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
```
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]


***

## Contributors

| Author(s) |
|-----------|
| [Aimery Thomas](https://github.com/a1mery)|

[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-remove-access-requests" aria-hidden="true" />
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions scripts/spo-remove-access-requests/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"name": "spo-remove-access-requests",
"source": "pnp",
"title": "Remove site access requests",
"shortDescription": "As a site owner, delete in bulk all the access requests from a SharePoint site.",
"url": "https://pnp.github.io/script-samples/spo-remove-access-requests/README.html",
"longDescription": [
"As a site owner, delete in bulk all the access requests from a SharePoint site using their status."
],
"creationDateTime": "2024-06-28",
"updateDateTime": "2024-06-28",
"products": [
"SharePoint"
],
"metadata": [
{
"key": "PNP-POWERSHELL",
"value": "2.4.0"
}
],
"categories": [
"Configure"
],
"tags": [
"Connect-PnPOnline",
"New-PnPBatch",
"Get-PnPList",
"Get-PnPListItem",
"Remove-PnPListItem",
"Invoke-PnPBatch",
"Disconnect-PnPOnline"
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-remove-access-requests/assets/preview.png",
"alt": ""
}
],
"authors": [
{
"gitHubAccount": "a1mery",
"pictureUrl": "https://github.com/a1mery.png",
"name": "Aimery Thomas"
}
],
"references": [
{
"name": "Want to learn more about PnP PowerShell and the cmdlets",
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
"url": "https://aka.ms/pnp/powershell"
}
]
}
]

0 comments on commit 920f45a

Please sign in to comment.