Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
retrieve sitemap
#Requires -Version 6.0
Set-StrictMode -Version Latest
function Get-SitemapUrl {
[OutputType([string[]])]
param(
[Parameter(Mandatory = $true)]
[string]$Url
)
$res = Invoke-Webrequest "$Url/sitemap.xml"
if ($res.StatusCode -ne 200) {
throw $res
}
[xml]$index = $res.Content
$sitemaps = $index.sitemapindex.sitemap.loc
[string[]]$urls = $sitemaps | Foreach-Object {
$eachRes = Invoke-Webrequest $_
[xml]$page = $eachRes.Content
Write-Output $page.urlset.url.loc
}
Write-Output $urls
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.