Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Returns all URLs and optional metadata from an XML Sitemap
Downloads an XML Sitemap and parses the content to retrieve all the information. If the file contains Sitemap Index entries those links will be followed as well.
Author: Michaël Hompus
License: This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 Generic License.
The URL for a XML Sitemap file
Indicates any Sitemap Index entries won't be followed
ConvertFrom-SiteMap.ps1 -Url
ConvertFrom-SiteMap.ps1 -Url -NoFollow
[parameter(Mandatory = $true, HelpMessage = "The URL for a XML Sitemap file")]
[parameter(HelpMessage = "Indicates any Sitemap Index entries won't be followed")]
Function ParseSitemap($url) {
Write-Verbose "Fetching file from $url"
$sitemap = Invoke-RestMethod $url -UseBasicParsing
Write-Verbose "Parsing sitemap"
if ($sitemap.sitemapindex -ne $null -and !$NoFollow) {
Write-Verbose "Following sitemapindex entries"
$sitemap.sitemapindex.sitemap.loc | ForEach-Object {
ParseSitemap -url $_
if ($sitemap.urlset -ne $null) {
Write-Verbose "Parsing urlset"
$result = ParseSitemap('')
$result | Export-Csv -path C:\temp\CSV-CurrentSitemap.csv -NoTypeInformation -Encoding UTF8
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.