|
| 1 | +--- |
| 2 | +plugin: add-to-gallery |
| 3 | +--- |
| 4 | + |
| 5 | +# Scan libraries for webhook and export to csv |
| 6 | + |
| 7 | +## Summary |
| 8 | + |
| 9 | +As part of the the pre migration assessment, it is important to identify all libraries that have webhooks configured. This script will scan all libraries in a site collection and export the libraries that have webhooks configured to a csv file. |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +# [PnP PowerShell](#tab/pnpps) |
| 15 | + |
| 16 | +```powershell |
| 17 | +
|
| 18 | +
|
| 19 | +#use this function to get the sites you want to check |
| 20 | +function GetSitesToCheck |
| 21 | +{ |
| 22 | + #$allsites = Get-PnPTenantSite -Connection $adminConn -Filter "Url -like 'https://contoso.sharepoint.com/'" -ErrorAction Stop |
| 23 | + $allsites = Get-PnPTenantSite -Connection $adminConn -ErrorAction Stop |
| 24 | + return $allsites |
| 25 | +} |
| 26 | +
|
| 27 | +
|
| 28 | +$adminUrl = "https://contoso-admin.sharepoint.com" |
| 29 | +$PnPClientId = "Your PnP Client ID" |
| 30 | +$adminConn = Connect-PnPOnline -Url $adminUrl -Interactive -ClientId $PnPClientId |
| 31 | +$outputPath = "C:\temp\" |
| 32 | +$sites = GetSitesToCheck |
| 33 | +$output = @() |
| 34 | +foreach ($site in $sites) |
| 35 | +{ |
| 36 | + $siteUrl = $site.Url |
| 37 | + $siteConn = Connect-PnPOnline -Url $siteUrl -Interactive -ClientId $PnPClientId |
| 38 | + $libraries = Get-PnPList | Where-Object {$_.BaseType -eq "DocumentLibrary"} |
| 39 | + foreach ($library in $libraries) |
| 40 | + { |
| 41 | + $webhooks = Get-PnPWebhookSubscription -List $library.Title |
| 42 | + foreach ($webhook in $webhooks) |
| 43 | + { |
| 44 | + Write-Host "Library $($library.Title) in site $($site.Title) has $($webhooks.Count) webhooks" |
| 45 | + $output += [PSCustomObject]@{ |
| 46 | + SiteUrl = $siteUrl |
| 47 | + SiteTitle = $site.Title |
| 48 | + LibraryTitle = $library.Title |
| 49 | + WebhookId = $webhook.Id |
| 50 | + WebhookExpirationDateTime = $webhook.ExpirationDateTime |
| 51 | + WebhookNotificationUrl = $webhook.NotificationUrl |
| 52 | + WebhookResource = $webhook.Resource |
| 53 | + WebhookClientState = $webhook.ClientState |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | +
|
| 59 | +$output | Export-Csv -Path "$outputPath\Webhooks.csv" -Encoding utf8BOM -Delimiter "|" -Force; |
| 60 | +
|
| 61 | +
|
| 62 | +``` |
| 63 | +[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)] |
| 64 | +*** |
| 65 | + |
| 66 | + |
| 67 | +## Contributors |
| 68 | + |
| 69 | +| Author(s) | |
| 70 | +|-----------| |
| 71 | +| Kasper Larsen | |
| 72 | + |
| 73 | +[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] |
| 74 | +<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-get-libraries-with-webhooks" aria-hidden="true" /> |
0 commit comments