PowerShell/scripts/list-executables.ps1

39 lines
1.1 KiB
PowerShell
Raw Normal View History

2023-10-31 12:33:36 +01:00
<#
2023-10-25 16:18:27 +02:00
.SYNOPSIS
2024-03-06 08:02:38 +01:00
Lists all executables in a dir tree
2023-10-25 16:18:27 +02:00
.DESCRIPTION
2024-03-06 08:02:38 +01:00
This PowerShell script scans a given directory tree and lists all executables with suffix .EXE.
2023-10-25 16:18:27 +02:00
.PARAMETER path
Specifies the path to the directory tree (current working directory by default)
.EXAMPLE
PS> ./list-executables.ps1 C:\Windows
2024-03-06 08:02:38 +01:00
C:\Windows\bfsvc.exe
2023-10-25 16:18:27 +02:00
...
2024-03-06 08:02:38 +01:00
Found 7967 executables within 📂C:\Windows in 168 sec.
2023-10-25 16:18:27 +02:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$path = "$PWD")
try {
$stopWatch = [system.diagnostics.stopwatch]::startNew()
2024-03-06 08:02:38 +01:00
Write-Progress "Listing executables within $path ..."
2023-10-25 16:18:27 +02:00
$path = Resolve-Path "$path"
[int]$count = 0
Get-ChildItem "$path" -attributes !Directory -recurse -force | Where-Object { $_.Name -like "*.exe" } | ForEach-Object {
2024-03-06 08:02:38 +01:00
"$($_.FullName)"
2023-10-25 16:18:27 +02:00
$count++
}
Write-Progress -completed " "
2024-03-06 08:02:38 +01:00
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✔️ Found $count executables within 📂$path in $elapsed sec."
2023-10-25 16:18:27 +02:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}