Get web part id in a classic page using PNP

Tanmoy Das 806 Reputation points
2021-01-06T01:30:21.327+00:00

Hi,

I have some classic pages and I want to get the id of a web part in those pages using PNP.

I have tried this but not working

$webparts = Get-PnPWebPart -ServerRelativePageUrl $url
foreach($webpart in $webparts)
{

 if($webpart.Webpart.title -like "xxxx")
 {
  $webpart.Webpart.Title
      $webpart.Id

 }
}

I can get the title but not the Id field.

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

Accepted answer
  1. Emily Du-MSFT 51,846 Reputation points Microsoft External Staff
    2021-01-06T09:39:04.793+00:00

    anonymous user

    Try below PowerShell.

    #Parameters  
    $SiteURL = "https://tenant.sharepoint.com/sites/emilytest"  
    $PageServerRelativeURL = "/sites/emilytest/SitePages/111.aspx"  
       
    #Connect to SharePoint Online site  
    Connect-PnPOnline -Url $SiteURL -UseWebLogin  
       
    #Get All Web parts from the page  
    $Webparts = Get-PnPWebPart -ServerRelativePageUrl $PageServerRelativeURL  
       
    #Iterate through webparts  
    ForEach($Webpart in $Webparts)   
    {  
      if($Webpart.Webpart.title -like "cal")      
      {  
        Write-Host "WebPart Id:" $Webpart.Id   
        Write-Host "Title:" $Webpart.WebPart.Title      
      }  
    }  
    

    Result:
    53779-1.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.