Created
August 21, 2015 09:51
-
-
Save AlexKasaku/0d572ceb16e25d62103c to your computer and use it in GitHub Desktop.
Remove redirect items that are no longer pointed at an existing item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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