Update check-symlinks.ps1

This commit is contained in:
Markus Fleschutz 2022-05-30 08:12:48 +02:00
parent bcb66d2445
commit e71741d12a

View File

@ -1,6 +1,6 @@
<# <#
.SYNOPSIS .SYNOPSIS
Checks every symlink in a folder Checks symlinks in a directory tree
.DESCRIPTION .DESCRIPTION
This PowerShell script checks every symlink in a folder (including subfolders). This PowerShell script checks every symlink in a folder (including subfolders).
It returns the number of broken symlinks as exit value. It returns the number of broken symlinks as exit value.
@ -22,7 +22,7 @@ try {
$StopWatch = [system.diagnostics.stopwatch]::startNew() $StopWatch = [system.diagnostics.stopwatch]::startNew()
$FullPath = Resolve-Path "$folder" $FullPath = Resolve-Path "$folder"
"⏳ Checking every symlink in 📂$FullPath ..." "⏳ Checking symlinks under 📂$FullPath ..."
[int]$NumTotal = [int]$NumBroken = 0 [int]$NumTotal = [int]$NumBroken = 0
Get-ChildItem $FullPath -recurse | Where { $_.Attributes -match "ReparsePoint" } | ForEach-Object { Get-ChildItem $FullPath -recurse | Where { $_.Attributes -match "ReparsePoint" } | ForEach-Object {
@ -32,7 +32,7 @@ try {
$path = $_.FullName + "\..\" + ($_ | Select-Object -ExpandProperty Target) $path = $_.FullName + "\..\" + ($_ | Select-Object -ExpandProperty Target)
$item = Get-Item $path -ErrorAction Ignore $item = Get-Item $path -ErrorAction Ignore
if (!$item) { if (!$item) {
"Bad $Symlink 🠆 $Target" "$Symlink 🠆 $Target is broken"
$NumBroken++ $NumBroken++
} }
} }
@ -51,4 +51,4 @@ try {
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }