mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-29 08:06:51 +01:00
Update check-symlinks.ps1
This commit is contained in:
parent
cae2904f3d
commit
71e4bc64f1
@ -20,8 +20,10 @@ param([string]$folder = "")
|
|||||||
try {
|
try {
|
||||||
if ($folder -eq "" ) { $folder = read-host "Enter the path to the folder" }
|
if ($folder -eq "" ) { $folder = read-host "Enter the path to the folder" }
|
||||||
|
|
||||||
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
$FullPath = Resolve-Path "$folder"
|
$FullPath = Resolve-Path "$folder"
|
||||||
write-progress "Checking every symlink in 📂$FullPath..."
|
"⏳ Checking every symlink in 📂$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 {
|
||||||
$Symlink = $_.FullName
|
$Symlink = $_.FullName
|
||||||
@ -30,14 +32,15 @@ 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) {
|
||||||
write-warning "Broken symlink $Symlink -> $Target"
|
"Bad $Symlink 🠆 $Target"
|
||||||
$NumBroken++
|
$NumBroken++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$NumTotal++
|
$NumTotal++
|
||||||
}
|
}
|
||||||
|
|
||||||
"✔️ $NumBroken out of $NumTotal symlinks are broken in 📂$FullPath"
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||||
|
"✔️ checked $NumTotal symlinks in 📂$FullPath ($NumBroken are broken) in $Elapsed sec"
|
||||||
exit $NumBroken
|
exit $NumBroken
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
||||||
|
Loading…
Reference in New Issue
Block a user