Get the JSON page content from all pages in a DXA implementation
$baseUrl = "http://localhost:82/odata.svc/" # Set the baseUrl to the URL of your Tridion Content Delivery web service
$ErrorActionPreference = "Stop"
Write-Output "Download list of pages..."
[xml]$feed= Invoke-WebRequest "http://localhost:82/odata.svc/PageContents"
$entries = $feed.feed.entry
Write-Output ("Found " + $entries.Count + " pages")
Write-Output "This script assumes all pages are JSON"
Write-Output "Download and save pages..."
foreach ($pageEntry in $entries)
{
$pageLink = $pageEntry.link | Where {$_.title -eq "Page" }
[string] $url = Invoke-WebRequest($baseUrl + $pageLink.href + "/Url/value")
$pageContent = $pageEntry.content.properties.Content
$pageContent = $pageContent | ConvertFrom-Json | ConvertTo-Json # pretty print Json
#$filename = "page-" + $pageEntry.content.properties.PublicationId.InnerText + "-" + $pageEntry.content.properties.PageId.InnerText + ".json"
$filename = "pages" + $url
$directory = Split-Path $filename
$void = new-item -ItemType directory $directory -Force
Write-Output ("writing " + $filename)
$pageContent | Out-File $filename
}
Write-Output "Done"