Find every page that contains a Modern Script Editor web part
Locate use of Modern Script Editor
Summary
Since the Modern Script Editor web part is impacted by the automatic disabling af Custom Scripting every 24 hours, it is a good idea to find all pages that contain this web part. This script will search through all pages in a site collection and return the pages that contain the Modern Script Editor web part.

#locate all page containing a Script Editor Web part
$url = "https://contoso.sharepoint.com/sites/somesite"
#login in a way that allows you to search all sites. I usually use -ManagedIdentity in Azure Automation/Function
$conn = Connect-PnPOnline -Url $url -Interactive -ReturnConnection -WarningAction Ignore
$IdForScriptEditorWebPart = "3a328f0a-99c4-4b28-95ab-fe0847f657a3"
$query = 'SPFxExtensionJson:"'+$IdForScriptEditorWebPart+'"'
$result = Invoke-PnPSearchQuery -Query $query -Connection $conn -All -SelectProperties "Path", "FileName"
$result.ResultRows.Count
#export to csv
$data = @()
foreach($row in $result.ResultRows)
{
$item = New-Object PSObject
$item | Add-Member -MemberType NoteProperty -Name "Path" -Value $row.Path
$item | Add-Member -MemberType NoteProperty -Name "FileName" -Value $row.FileName
$data += $item
}
$data | Export-Csv -Path "C:\temp\searchresult.csv" -NoTypeInformation
Contributors
| Author(s) |
|---|
| Kasper Larsen |
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.