Export all WebParts from modern site pages using Microsoft 365 CLI

There are a lot of scenarios for the developers and administrators who needs this script to fetch the list of modern web parts used in all modern site pages.
  • If you have a lot of modern site pages in your SharePoint and you want to know, which page contains which web parts.
  • If your want to delete the specific modern web parts from all the Site pages or some of the site pages.
  • You may have a requirement to change certain properties of some of the web parts in some of the modern pages.

Like above there are a lot of scenarios for the developers and administrators who needs this script should fetch the list of modern web parts used in all modern site pages. To accomplish these goals, I have prepared the sample Microsoft CLI script to export all the pages with the web part information from a SharePoint site.

I have used the combination of below Microsoft CLI commands to export all the details,

Fetch the list of modern pages
m365 spo page list --webUrl <SharePoint Site URL>

Fetch the list of associated web parts/controls on a modern page

m365 spo page control list --webUrl <SharePoint site URL> --name <Page Name>

Sample Script

Shantha Kumar
Shantha Kumar
Articles: 280