mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-16 06:58:18 +02:00
Added scan-folder.ps1
This commit is contained in:
parent
467332f0fe
commit
6b9e8582a4
47
scripts/scan-folder.ps1
Normal file
47
scripts/scan-folder.ps1
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Scans a folder for viruses
|
||||||
|
.DESCRIPTION
|
||||||
|
This PowerShell script scans the given folder (including subfolders) for viruses. Requires the installation of ESET or Windows Defender.
|
||||||
|
.PARAMETER path
|
||||||
|
Specifies the file path to the folder (default is working directory).
|
||||||
|
.EXAMPLE
|
||||||
|
PS> ./scan-folder.ps1 C:\Windows
|
||||||
|
⏳ Scanning folder with ESET Antivirus...
|
||||||
|
...
|
||||||
|
.LINK
|
||||||
|
https://github.com/fleschutz/PowerShell
|
||||||
|
.NOTES
|
||||||
|
Author: Markus Fleschutz | License: CC0
|
||||||
|
#>
|
||||||
|
|
||||||
|
param([string]$path = "$PWD")
|
||||||
|
|
||||||
|
try {
|
||||||
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
|
|
||||||
|
if (-not(Test-Path $path -pathType container)) { throw "Invalid file path: $path" }
|
||||||
|
$path = Resolve-Path $path
|
||||||
|
|
||||||
|
if (Test-Path "C:\Program Files\ESET\ESET Security\ecls.exe" -pathType leaf) {
|
||||||
|
|
||||||
|
"⏳ Scanning folder with ESET Antivirus..."
|
||||||
|
& "C:\Program Files\ESET\ESET Security\ecls.exe" $path
|
||||||
|
if ($lastExitCode -ne 0) { throw "ESET Antivirus failed with exit code $lastExitCode - POTENTIAL DANGER!!!" }
|
||||||
|
|
||||||
|
} elseif (Test-Path "C:\Program Files\Windows Defender\MpCmdRun.exe" -pathType leaf) {
|
||||||
|
|
||||||
|
"⏳ Scanning folder with Windows Defender..."
|
||||||
|
& "C:\Program Files\Windows Defender\MpCmdRun.exe" -Scan -ScanType 2 -File $path
|
||||||
|
if ($lastExitCode -ne 0) { throw "Windows Defender failed with exit code $lastExitCode - POTENTIAL DANGER !!!" }
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw "Found no ESET or Windows Defender - please install one."
|
||||||
|
}
|
||||||
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
|
"✅ Scanned 📂$path in $($elapsed)s: No malware found."
|
||||||
|
exit 0 # success
|
||||||
|
} catch {
|
||||||
|
"⚠️ Error: $($Error[0])"
|
||||||
|
exit 1
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user