PowerShell/scripts/list-hidden-files.ps1

38 lines
1018 B
PowerShell
Raw Normal View History

2023-10-31 11:25:11 +01:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2023-10-24 09:45:23 +02:00
Lists all hidden files in a directory tree
2021-07-13 21:10:02 +02:00
.DESCRIPTION
2023-10-24 09:45:23 +02:00
This PowerShell script scans a directory tree and lists all hidden files.
.PARAMETER path
Specifies the path to the directory tree (default is current working dir)
2021-07-13 21:10:02 +02:00
.EXAMPLE
2023-10-24 09:45:23 +02:00
PS> ./list-hidden-files.ps1 C:\Windows
...
Found 256 hidden files within 📂C:\Windows in 40 sec
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
2022-01-29 12:47:46 +01:00
.NOTES
2022-09-06 21:42:04 +02:00
Author: Markus Fleschutz | License: CC0
2021-02-27 11:37:50 +01:00
#>
2023-10-24 09:45:23 +02:00
param([string]$path = "$PWD")
2021-02-27 11:37:50 +01:00
try {
2023-10-24 09:45:23 +02:00
$stopWatch = [system.diagnostics.stopwatch]::startNew()
2021-04-21 19:53:52 +02:00
2023-10-24 09:45:23 +02:00
$path = Resolve-Path "$path"
Write-Progress "Scanning $path for hidden files..."
[int]$count = 0
Get-ChildItem "$path" -attributes Hidden -recurse | Foreach-Object {
2023-10-24 09:55:23 +02:00
"📄$($_.FullName)"
2023-10-24 09:45:23 +02:00
$count++
2021-02-27 11:37:50 +01:00
}
2023-10-24 09:45:23 +02:00
Write-Progress -completed " "
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✔️ Found $count hidden files within 📂$path in $elapsed sec"
2021-09-27 10:09:45 +02:00
exit 0 # success
2021-02-27 11:37:50 +01:00
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-02-27 11:37:50 +01:00
exit 1
}