test the script
# ==========================================
# Downloads Folder Scan & Report Script
# ==========================================
# --- CONFIGURATION ---
# Define the Discord webhook URL
$webhookUrl =
"[Link]
q2fzz9Uu2ddW1waJTYMBq-TYA-RJV0JCkeQaBcX"
# Define the Downloads folder path
$downloadsPath = "$env:USERPROFILE\Downloads"
# --- SYSTEM INFORMATION COLLECTION ---
$computerName = $env:COMPUTERNAME
$os = (Get-WmiObject Win32_OperatingSystem).Caption
$cpu = (Get-WmiObject Win32_Processor).Name
$ram = [math]::round((Get-WmiObject Win32_ComputerSystem).TotalPhysicalMemory /
1GB, 2)
# --- START SCAN ON DOWNLOADS FOLDER ---
Write-Output "Starting Windows Defender scan on Downloads folder: $downloadsPath"
# Use a custom scan on the specified folder
Start-MpScan -ScanPath $downloadsPath -ScanType CustomScan
# Wait for the scan to complete or at least for results to update.
# Adjust this delay as necessary.
Start-Sleep -Seconds 30
# --- RETRIEVE SCAN RESULTS ---
try {
$threats = Get-MpThreatDetection
} catch {
Write-Output "Error retrieving threat detection results: $_"
$threats = @()
}
if ($threats -and $[Link] -gt 0) {
$threatDetails = $threats | ForEach-Object {
# Note: The Resources property may contain multiple entries;
# here we show the first one if available.
$resource = if ($_.Resources -and $_.[Link] -gt 0)
{ $_.Resources[0] } else { "N/A" }
"Threat: $($_.ThreatName) | Action: $($_.ActionSuccess) | Resource:
$resource"
} -join "`n"
} else {
$threatDetails = "No threats detected in Downloads folder."
}
# --- ASSEMBLE THE REPORT PAYLOAD ---
$payloadContent = @"
**System Scan Report**
Computer Name: $computerName
OS: $os
CPU: $cpu
RAM: $ram GB
**Downloads Folder Scan ($downloadsPath):**
$threatDetails
"@
$payload = @{
content = $payloadContent
} | ConvertTo-Json
# --- SEND THE REPORT TO THE DISCORD WEBHOOK ---
try {
Invoke-RestMethod -Uri $webhookUrl -Method Post -Body $payload -ContentType
"application/json"
Write-Output "Scan report sent to webhook successfully."
} catch {
Write-Output "Error sending report to webhook: $_"
}