I am able to read the SharePoint web part properties and values using below code and able to export it. But after exporting, when i open the file could not find exact values.
Find the code below:
$userId = ""
$pwd = Read-Host -Prompt "Enter password" -AsSecureString
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd)
$ctx.credentials = $creds
#Not required for on premise site - End
#page to be viewed
$pageName = "TestPage1.aspx"
#Get the page
$file = $ctx.Web.GetFileByServerRelativeUrl("/Pages/TestPage1.aspx")
$ctx.Load($file)
$ctx.ExecuteQuery()
#Get all the webparts
Write-Host "Retrieving webparts"
$wpManager = $file.GetLimitedWebPartManager([Microsoft.SharePoint.Client.WebParts.PersonalizationScope]::Shared)
$webparts = $wpManager.Webparts
$ctx.Load($webparts)
$ctx.ExecuteQuery()
if($webparts.Count -gt 0){
Write-Host "Looping through all webparts"
foreach($webpart in $webparts){
$ctx.Load($webpart.WebPart.Properties)
$ctx.ExecuteQuery()
$propValues = $webpart.WebPart.Properties.FieldValues
Write-Host "ID: $webpart.id"
foreach($property in $propValues){
Write-Host "Title: " $property.Title
Write-Host "Description: " $property.Description
Write-Host "Chrome Type: " $property.ChromeType
$listItemData = @{
"Webpart Title" = $property.Title
"Webpart Description" = $property.Description
"Chrome Type" = $property.ChromeType
}
New-Object PSObject -Property $listItemData
}
}
}
$listItemData |Export-Csv -NoTypeInformation -Path "Your CSV file path"
Output of code:
Webpart Title Chrome Type Webpart Description
------------- ----------- -------------------
Web Part Page Title Bar 2
Content Editor 0 Allows authors to enter rich text content.
Script Editor 2 Allows authors to insert HTML snippets or scripts.
Image Viewer 0 Displays a specified image.
Exported CSV:
why i am not able to get the output values??