mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-17 15:38:20 +02:00
Merge branch 'master' of github.com:fleschutz/PowerShell
This commit is contained in:
commit
47aa344912
@ -1,28 +1,27 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Checks symlinks in a directory tree
|
Checks symlinks in a folder
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script checks every symlink in a folder (including subfolders).
|
This PowerShell script checks every symbolic link 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.
|
||||||
.PARAMETER folder
|
.PARAMETER folder
|
||||||
Specifies the path to the folder
|
Specifies the path to the folder
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./check-symlinks .
|
PS> ./check-symlinks C:\Users
|
||||||
✔️ found 2 broken symlinks at 📂/home/markus (10 total) in 17 sec
|
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$folder = "")
|
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()
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
$FullPath = Resolve-Path "$folder"
|
$FullPath = Resolve-Path "$Folder"
|
||||||
"⏳ Checking symlinks under 📂$FullPath ..."
|
"⏳ Checking symlinks at 📂$FullPath including subfolders..."
|
||||||
|
|
||||||
[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,8 +31,8 @@ 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) {
|
||||||
"$Symlink 🠆 $Target is broken"
|
|
||||||
$NumBroken++
|
$NumBroken++
|
||||||
|
"Broken symlink #$($NumBroken): $Symlink ⭢ $Target"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$NumTotal++
|
$NumTotal++
|
||||||
@ -44,8 +43,10 @@ try {
|
|||||||
"✔️ found no symlink at 📂$FullPath in $Elapsed sec"
|
"✔️ found no symlink at 📂$FullPath in $Elapsed sec"
|
||||||
} elseif ($NumBroken -eq 0) {
|
} elseif ($NumBroken -eq 0) {
|
||||||
"✔️ found $NumTotal valid symlinks at 📂$FullPath in $Elapsed sec"
|
"✔️ found $NumTotal valid symlinks at 📂$FullPath in $Elapsed sec"
|
||||||
|
} elseif ($NumBroken -eq 1) {
|
||||||
|
"✔️ found $NumBroken broken symlink out of $NumTotal at 📂$FullPath in $Elapsed sec"
|
||||||
} else {
|
} else {
|
||||||
"✔️ found $NumBroken broken symlinks at 📂$FullPath ($NumTotal total) in $Elapsed sec"
|
"✔️ found $NumBroken broken symlinks out of $NumTotal at 📂$FullPath in $Elapsed sec"
|
||||||
}
|
}
|
||||||
exit $NumBroken
|
exit $NumBroken
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user