-
Notifications
You must be signed in to change notification settings - Fork 6
/
Report-CustomActionUsage.ps1
92 lines (71 loc) · 3.91 KB
/
Report-CustomActionUsage.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<#
Microsoft provides programming examples for illustration only, without warranty either expressed or
implied, including, but not limited to, the implied warranties of merchantability and/or fitness
for a particular purpose. We grant You a nonexclusive, royalty-free right to use and modify the
Sample Code and to reproduce and distribute the object code form of the Sample Code, provided that
You agree: (i) to not use Our name, logo, or trademarks to market Your software product in which the
Sample Code is embedded; (ii) to include a valid copyright notice on Your software product in which
the Sample Code is embedded; and (iii) to indemnify, hold harmless, and defend Us and Our suppliers
from and against any claims or lawsuits, including attorneys' fees, that arise or result from the
use or distribution of the Sample Code.
#>
<#
.SYNOPSIS
Scan all site collections within the tenant to generate a report on every site-scoped custom action.
Generates a CSV report containing details about every custom action that was found.
.DESCRIPTION
Scan all site collections within the tenant to generate a report on every site-scoped custom action.
Generates a CSV report containing details about every custom action that was found.
NOTE: This script requires the PowerShell module 'SharePointPnPPowerShellOnline' to be installed. If it is missing, the script will attempt to install it.
RECOMMENDATION: Add administrator username and password for your tenant to Windows Credential Manager before running script.
https://github.com/SharePoint/PnP-PowerShell/wiki/How-to-use-the-Windows-Credential-Manager-to-ease-authentication-with-PnP-PowerShell
.PARAMETER TenantRootSiteUrl
SharePoint Tenant Root Site URL
.EXAMPLE
.\Report-CustomActionUsage.ps1 -TenantRootSiteUrl "https://tenant.sharepoint.com"
Scan all site collections within the tenant and generate a CSV report containing every site-scoped custom action.
#>
param(
[parameter(Mandatory = $true)]$TenantRootSiteUrl
)
#############################################
$module = Get-Module -Name SharePointPnPPowerShellOnline -ListAvailable
if ($null -eq $module) {
Write-Output "Installing PowerShell Module: SharePointPnPPowerShellOnline"
Install-Module -Name SharePointPnPPowerShellOnline -Force -AllowClobber -Confirm:$false
}
Import-Module -Name SharePointPnPPowerShellOnline -WarningAction Ignore
#############################################
Write-Host "Connecting to Tenant Root Site URL: $TenantRootSiteUrl"
Connect-PnPOnline -Url $TenantRootSiteUrl
$excludedTemplates = @("SPSMSITEHOST#0") #MySite Host
$excludedTemplates += "GROUP#0" #Modern Group Site
$excludedTemplates += "SITEPAGEPUBLISHING#0" #Modern Communication Site
$excludedTemplates += "STS#3" #Modern Team Site (not group connected)
Write-Host "Fetching list of all Site Collections"
$sites = Get-PnPTenantSite | Where-Object { $excludedTemplates -notcontains $_.Template }
Write-Host "Found $($sites.Count) Site Collections"
$timestamp = (Get-Date).ToString("yyyyMMdd.HHmm")
$csvName = "CustomActionUsage-$timestamp.csv"
foreach ($site in $sites) {
Write-Host " SITE: $($site.Url)"
Connect-PnPOnline -Url $site.Url
$customActions = @(Get-PnPCustomAction -Scope Site)
if ($customActions.Count -gt 0) {
Write-Host " Found $($customActions.Count) custom actions"
foreach ($customAction in $customActions) {
$reportRow = @{
SiteUrl = $site.Url
CALocation = $customAction.Location
CAId = $customAction.Id
CAName = $customAction.Name
CADescription = $customAction.Description
CAScriptBlock = $customAction.ScriptBlock
CAScriptSrc = $customAction.ScriptSrc
CASequence = $customAction.Sequence
CAGroup = $customAction.Group
}
([PSCustomObject]$reportRow) | Export-Csv -Path $csvName -NoTypeInformation -Append
}
}
}