Monday, February 11, 2019

Locate pages where a particular web part is being using on modern SharePoint sites

close up photography of LED bulb on sand

This post was inspired by, but I’ve simplified things a bit as some of the steps are not needed. I also opted to use PnP PowerShell.

There is no defined API to find usages of specific SharePoint Framework web parts on modern pages. But fortunately for us the id of each web part is included in the searchable content for modern pages (no need to map up a particular refinable string for this as per the inspired post).

Note: Only pages you have access to will be listed – if you need all pages you can elevate search permissions using app-only permissions, which is (dangerous) different story.

The id for the PnP search result web part is 42ad2740-3c60-49cf-971a-c44e33511b93, which means the below query will list return pages where this web part is used.

FileExtension:aspx 42ad2740-3c60-49cf-971a-c44e33511b93

Putting this into PnP PowerShell to return absolutely all (searchable) pages using this web part we get:

Submit-PnPSearchQuery -Query "FileExtension:aspx 42ad2740-3c60-49cf-971a-c44e33511b93" -All -RelevantResults | select OriginalPath

So how do you go about find the id of a particular web part? The easiest approach unless you are the developer of the web part you are looking for is to create a new page and add the web part to that page. If you however are the developer of the web part, you have the id in the manifest file.

Say you create a page which ends up as /SitePages/my-page.aspx, then you can list all custom parts of that page with the below command after you connect to the site with Connect-PnPOnline.

Get-PnPClientSideComponent -Page "my-page"|? Title -ne $null  |select Title,WebPartId

Output from the above command could look like:

Title                        WebPartId
-----                        ---------
Search Results with Refiners 42ad2740-3c60-49cf-971a-c44e33511b93

..and there you have the id.

Here’s a list of id’s for a bunch of the out of the box web parts:

  • ContentRollup: "daf0b71c-6de8-4ef7-b511-faae7c388708"
  • BingMap: "e377ea37-9047-43b9-8cdb-a761be2f8e09"
  • ContentEmbed: "490d7c76-1824-45b2-9de3-676421c997fa"
  • DocumentEmbed: "b7dd04e1-19ce-4b24-9132-b60a1c2b910d"
  • Image: "d1d91016-032f-456d-98a4-721247c305e8"
  • ImageGallery: "af8be689-990e-492a-81f7-ba3e4cd3ed9c"
  • LinkPreview: "6410b3b6-d440-4663-8744-378976dc041e"
  • NewsFeed: "0ef418ba-5d19-4ade-9db0-b339873291d0"
  • NewsReel: "a5df8fdf-b508-4b66-98a6-d83bc2597f63"
  • PowerBIReportEmbed: "58fcd18b-e1af-4b0a-b23b-422c2c52d5a2"
  • QuickChart: "91a50c94-865f-4f5c-8b4e-e49659e69772"
  • SiteActivity: "eb95c819-ab8f-4689-bd03-0c2d65d47b1f"
  • VideoEmbed: "275c0095-a77e-4f6d-a2a0-6a7626911518"
  • YammerEmbed: "31e9537e-f9dc-40a4-8834-0e3b7df418bc"
  • Events: "20745d7d-8581-4a6c-bf26-68279bc123fc"
  • GroupCalendar: "6676088b-e28e-4a90-b9cb-d0d0303cd2eb"
  • Hero: "c4bd7b2f-7b6e-4599-8485-16504575f590"
  • List: "f92bf067-bc19-489e-a556-7fe95f508720"
  • PageTitle: "cbe7b0a9-3504-44dd-a3a3-0e5cacd07788"
  • People: "7f718435-ee4d-431c-bdbf-9c4ff326f46e"
  • QuickLinks: "c70391ea-0b10-4ee9-b2b4-006d3fcad0cd"
  • CustomMessageRegion: "71c19a43-d08c-4178-8218-4df8554c0b0e"
  • Divider: "2161a1c6-db61-4731-b97c-3cdb303f7cbb"
  • MicrosoftForms: "b19b3b9e-8d13-4fec-a93c-401a091c0707"
  • Spacer: "8654b779-4886-46d4-8ffb-b5ed960ee986"
  • ClientWebPart: "243166f5-4dc3-4fe2-9df2-a7971b546a0a"
  • PowerApps: "9d7e898c-f1bb-473a-9ace-8b415036578b"
  • CodeSnippet: "7b317bca-c919-4982-af2f-8399173e5a1e"
  • PageFields: "cf91cf5d-ac23-4a7a-9dbc-cd9ea2a4e859"
  • Weather: "868ac3c3-cad7-4bd6-9a1c-14dc5cc8e823"
  • YouTube: "544dd15b-cf3c-441b-96da-004d5a8cea1d"
  • MyDocuments: "b519c4f1-5cf7-4586-a678-2f1c62cc175a"
  • YammerFullFeed: "cb3bfe97-a47f-47ca-bffb-bb9a5ff83d75"
  • CountDown: "62cac389-787f-495d-beca-e11786162ef4"
  • ListProperties: "a8cd4347-f996-48c1-bcfb-75373fed2a27"
  • MarkDown: "1ef5ed11-ce7b-44be-bc5e-4abd55101d16"
  • Planner: "39c4c1c2-63fa-41be-8cc2-f6c0b49b253d"

Photo by Glen Carrie at Unsplash