PowerShell/docs/list-executables.md

87 lines
2.2 KiB
Markdown
Raw Permalink Normal View History

2024-11-08 12:38:20 +01:00
The *list-executables.ps1* Script
===========================
2023-12-07 20:24:45 +01:00
2024-03-27 17:36:59 +01:00
This PowerShell script scans a given directory tree and lists all executables with suffix .EXE.
2023-12-07 20:24:45 +01:00
Parameters
----------
```powershell
2024-11-08 12:35:11 +01:00
/home/markus/Repos/PowerShell/scripts/list-executables.ps1 [[-path] <String>] [<CommonParameters>]
2023-12-07 20:24:45 +01:00
-path <String>
Specifies the path to the directory tree (current working directory by default)
Required? false
Position? 1
Default value "$PWD"
Accept pipeline input? false
Accept wildcard characters? false
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
Example
-------
```powershell
PS> ./list-executables.ps1 C:\Windows
2024-03-27 17:36:59 +01:00
C:\Windows\bfsvc.exe
2023-12-07 20:24:45 +01:00
...
2024-11-08 12:35:11 +01:00
✅ Found 7967 executables within 📂C:\Windows in 168 sec.
2023-12-07 20:24:45 +01:00
```
Notes
-----
Author: Markus Fleschutz | License: CC0
Related Links
-------------
https://github.com/fleschutz/PowerShell
Script Content
--------------
```powershell
<#
.SYNOPSIS
2024-03-27 17:36:59 +01:00
Lists all executables in a dir tree
2023-12-07 20:24:45 +01:00
.DESCRIPTION
2024-03-27 17:36:59 +01:00
This PowerShell script scans a given directory tree and lists all executables with suffix .EXE.
2023-12-07 20:24:45 +01:00
.PARAMETER path
Specifies the path to the directory tree (current working directory by default)
.EXAMPLE
PS> ./list-executables.ps1 C:\Windows
2024-03-27 17:36:59 +01:00
C:\Windows\bfsvc.exe
2023-12-07 20:24:45 +01:00
...
2024-11-08 12:35:11 +01:00
✅ Found 7967 executables within 📂C:\Windows in 168 sec.
2023-12-07 20:24:45 +01: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-27 17:36:59 +01:00
Write-Progress "Listing executables within $path ..."
2023-12-07 20:24:45 +01:00
$path = Resolve-Path "$path"
[int]$count = 0
Get-ChildItem "$path" -attributes !Directory -recurse -force | Where-Object { $_.Name -like "*.exe" } | ForEach-Object {
2024-03-27 17:36:59 +01:00
"$($_.FullName)"
2023-12-07 20:24:45 +01:00
$count++
}
Write-Progress -completed " "
2024-03-27 17:36:59 +01:00
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
2024-11-08 12:35:11 +01:00
"✅ Found $count executables within 📂$path in $elapsed sec."
2023-12-07 20:24:45 +01:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
```
2024-11-20 11:52:20 +01:00
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:55)*