Update check-symlinks.ps1

This commit is contained in:
Markus Fleschutz 2021-10-01 13:03:02 +02:00 committed by GitHub
parent 622132503d
commit a4a09819a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@
.SYNOPSIS
check-symlinks.ps1 [<DirTree>]
.DESCRIPTION
Checks every symlink in a directory tree
Checks every symlink in a directory tree.
.EXAMPLE
PS> ./check-symlinks C:\MyApp
.LINK
@ -16,9 +16,10 @@ param([string]$DirTree = "")
try {
if ($DirTree -eq "" ) { $DirTree = read-host "Enter the path to the directory tree" }
write-progress "Checking symlinks in $DirTree..."
$FullPath = Resolve-Path "$DirTree"
write-progress "Checking every symlink in 📂$FullPath..."
[int]$NumTotal = [int]$NumBroken = 0
Get-ChildItem $DirTree -recurse | Where { $_.Attributes -match "ReparsePoint" } | ForEach-Object {
Get-ChildItem $FullPath -recurse | Where { $_.Attributes -match "ReparsePoint" } | ForEach-Object {
$Symlink = $_.FullName
$Target = ($_ | Select-Object -ExpandProperty Target -ErrorAction Ignore)
if ($Target) {
@ -32,7 +33,7 @@ try {
$NumTotal++
}
"✔️ $NumBroken out of $NumTotal symlinks are broken in 📂$DirTree"
"✔️ $NumBroken out of $NumTotal symlinks are broken in 📂$FullPath"
exit $NumBroken
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"