Skip to content

Instantly share code, notes, and snippets.

@dhmacher
Last active July 26, 2022 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dhmacher/4ed506ab1e369b5b582123209900d599 to your computer and use it in GitHub Desktop.
Save dhmacher/4ed506ab1e369b5b582123209900d599 to your computer and use it in GitHub Desktop.
Validate all image URLs in a WordPress blog export
# Export your WordPress blog to an XML file. Then:
$xmlFile = "./export/sqlsundaycom.wordpress.2021-05-23.001.xml"
$matches = Select-String -Path $xmlFile -Pattern '(?<=src\=\")http(.*?)(?=\")' -AllMatches `
| % { $_.Matches }
| % { $_.Value }
| Sort-Object -Unique
foreach ($url in $matches) {
#$url
$res = Invoke-WebRequest -Uri $url -Method "HEAD" -SkipHttpErrorCheck
if ($res.StatusCode -ne 200) {
Write-Error ("ERROR: Status "+$res.StatusCode+": "+$url)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment