Skip to content

Instantly share code, notes, and snippets.

@AlexKasaku
Created August 21, 2015 09:51
Show Gist options
  • Save AlexKasaku/0d572ceb16e25d62103c to your computer and use it in GitHub Desktop.
Save AlexKasaku/0d572ceb16e25d62103c to your computer and use it in GitHub Desktop.
Remove redirect items that are no longer pointed at an existing item
<#
.SYNOPSIS
Removes all Redirect URLs that do not have a valid destination
.NOTES
Alex Washtell
#>
# HasReference determines if the specified item is referenced by any other item.
filter NoValidDestination {
$itemId = $_."Redirect To"
if (!$itemId) {
$_
}
else {
$destination = get-item master: -ID $itemId
if (!$destination) {
$_
}
}
}
Get-ChildItem -Recurse | Where TemplateName -eq "Redirect Url" | NoValidDestination | Remove-Item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment