mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-01-23 14:18:38 +01:00
Update check-symlinks.ps1
This commit is contained in:
parent
622132503d
commit
a4a09819a0
@ -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))"
|
||||
|
Loading…
Reference in New Issue
Block a user