
11,700 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
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:
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.