mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-29 16:16:47 +01:00
Update check-symlinks.ps1
This commit is contained in:
parent
f0bc1b4160
commit
8f193bc914
@ -29,7 +29,7 @@ check-mac-address.ps1, checks the given MAC address for validity
|
|||||||
check-ping.ps1, checks the ping latency to the internet
|
check-ping.ps1, checks the ping latency to the internet
|
||||||
check-subnet-mask.ps1, checks the given subnet mask for validity
|
check-subnet-mask.ps1, checks the given subnet mask for validity
|
||||||
check-swap-space.ps1, checks the swap space for free space left
|
check-swap-space.ps1, checks the swap space for free space left
|
||||||
check-symlinks.ps1, checks every symlink in the given directory tree
|
check-symlinks.ps1, checks every symlink in a directory tree
|
||||||
check-weather.ps1, checks the current weather for critical values
|
check-weather.ps1, checks the current weather for critical values
|
||||||
check-windows-system-files.ps1, checks the validity of the Windows system files
|
check-windows-system-files.ps1, checks the validity of the Windows system files
|
||||||
check-xml-file.ps1, checks the given XML file for validity
|
check-xml-file.ps1, checks the given XML file for validity
|
||||||
|
|
@ -142,7 +142,7 @@ Mega Collection of PowerShell Scripts
|
|||||||
| [cd-up3.ps1](Scripts/cd-up3.ps1) | Change the working directory to three directory levels up | [Help](Docs/cd-up3.ps1.md) |
|
| [cd-up3.ps1](Scripts/cd-up3.ps1) | Change the working directory to three directory levels up | [Help](Docs/cd-up3.ps1.md) |
|
||||||
| [cd-up4.ps1](Scripts/cd-up4.ps1) | Change the working directory to four directory levels up | [Help](Docs/cd-up4.ps1.md) |
|
| [cd-up4.ps1](Scripts/cd-up4.ps1) | Change the working directory to four directory levels up | [Help](Docs/cd-up4.ps1.md) |
|
||||||
| [cd-videos.ps1](Scripts/cd-videos.ps1) | Change the working directory to the user's videos folder | [Help](Docs/cd-videos.ps1.md) |
|
| [cd-videos.ps1](Scripts/cd-videos.ps1) | Change the working directory to the user's videos folder | [Help](Docs/cd-videos.ps1.md) |
|
||||||
| [check-symlinks.ps1](Scripts/check-symlinks.ps1) | Checks every symlink in the given directory tree | [Help](Docs/check-symlinks.ps1.md) |
|
| [check-symlinks.ps1](Scripts/check-symlinks.ps1) | Checks every symlink in a directory tree | [Help](Docs/check-symlinks.ps1.md) |
|
||||||
| [check-xml-file.ps1](Scripts/check-xml-file.ps1) | Checks the given XML file for validity | [Help](Docs/check-xml-file.ps1.md) |
|
| [check-xml-file.ps1](Scripts/check-xml-file.ps1) | Checks the given XML file for validity | [Help](Docs/check-xml-file.ps1.md) |
|
||||||
| [clear-recycle-bin.ps1](Scripts/clear-recycle-bin.ps1) | Removes the content of the recycle bin folder (can not be undo!) | [Help](Docs/clear-recycle-bin.ps1.md) |
|
| [clear-recycle-bin.ps1](Scripts/clear-recycle-bin.ps1) | Removes the content of the recycle bin folder (can not be undo!) | [Help](Docs/clear-recycle-bin.ps1.md) |
|
||||||
| [copy-photos-sorted.ps1](Scripts/copy-photos-sorted.ps1) | Copy image files sorted by year and month | [Help](Docs/copy-photos-sorted.ps1.md) |
|
| [copy-photos-sorted.ps1](Scripts/copy-photos-sorted.ps1) | Copy image files sorted by year and month | [Help](Docs/copy-photos-sorted.ps1.md) |
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
check-symlinks.ps1 [<dir-tree>]
|
check-symlinks.ps1 [<DirTree>]
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Checks every symlink in the given directory tree.
|
Checks every symlink in a directory tree
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> .\check-symlinks.ps1 C:\MyApp
|
PS> .\check-symlinks.ps1 C:\MyApp
|
||||||
.LINK
|
.LINK
|
||||||
@ -13,13 +13,11 @@
|
|||||||
|
|
||||||
param([string]$DirTree = "")
|
param([string]$DirTree = "")
|
||||||
|
|
||||||
if ($DirTree -eq "" ) {
|
|
||||||
$DirTree = read-host "Enter the path to the directory tree"
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if ($DirTree -eq "" ) { $DirTree = read-host "Enter the path to the directory tree" }
|
||||||
|
|
||||||
write-progress "Checking symlinks in $DirTree..."
|
write-progress "Checking symlinks in $DirTree..."
|
||||||
[int]$SymlinksTotal = [int]$SymlinksBroken = 0
|
[int]$NumTotal = [int]$NumBroken = 0
|
||||||
Get-ChildItem $DirTree -recurse | Where { $_.Attributes -match "ReparsePoint" } | ForEach-Object {
|
Get-ChildItem $DirTree -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)
|
||||||
@ -28,13 +26,13 @@ try {
|
|||||||
$item = Get-Item $path -ErrorAction Ignore
|
$item = Get-Item $path -ErrorAction Ignore
|
||||||
if (!$item) {
|
if (!$item) {
|
||||||
write-warning "Broken symlink: $Symlink -> $Target"
|
write-warning "Broken symlink: $Symlink -> $Target"
|
||||||
$SymlinksBroken++
|
$NumBroken++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$SymlinksTotal++
|
$NumTotal++
|
||||||
}
|
}
|
||||||
|
|
||||||
"✔️ found $SymlinksTotal symlinks total, $SymlinksBroken symlinks are broken"
|
"✔️ $NumBroken out of $NumTotal symlinks are broken in 📂$DirTree"
|
||||||
exit $SymlinksBroken
|
exit $SymlinksBroken
|
||||||
} catch {
|
} catch {
|
||||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user