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
|
.SYNOPSIS
|
||||||
check-symlinks.ps1 [<DirTree>]
|
check-symlinks.ps1 [<DirTree>]
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Checks every symlink in a directory tree
|
Checks every symlink in a directory tree.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./check-symlinks C:\MyApp
|
PS> ./check-symlinks C:\MyApp
|
||||||
.LINK
|
.LINK
|
||||||
@ -16,9 +16,10 @@ param([string]$DirTree = "")
|
|||||||
try {
|
try {
|
||||||
if ($DirTree -eq "" ) { $DirTree = read-host "Enter the path to the directory tree" }
|
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
|
[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
|
$Symlink = $_.FullName
|
||||||
$Target = ($_ | Select-Object -ExpandProperty Target -ErrorAction Ignore)
|
$Target = ($_ | Select-Object -ExpandProperty Target -ErrorAction Ignore)
|
||||||
if ($Target) {
|
if ($Target) {
|
||||||
@ -32,7 +33,7 @@ try {
|
|||||||
$NumTotal++
|
$NumTotal++
|
||||||
}
|
}
|
||||||
|
|
||||||
"✔️ $NumBroken out of $NumTotal symlinks are broken in 📂$DirTree"
|
"✔️ $NumBroken out of $NumTotal symlinks are broken in 📂$FullPath"
|
||||||
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