[CmdletBinding()] param( [ValidateRange(1, 1000)] [int]$Max = 100, [switch]$IncludeMicrosoft, [string]$Csv ) $ErrorActionPreference = 'Stop' if (-not (Get-Command Get-ScheduledTask -ErrorAction SilentlyContinue)) { Write-Error 'Модуль ScheduledTasks недоступен.' exit 2 } $tasks = @(Get-ScheduledTask -ErrorAction SilentlyContinue) if (-not $IncludeMicrosoft) { $tasks = @($tasks | Where-Object { $_.TaskPath -notlike '\Microsoft\*' }) } $results = @() foreach ($task in $tasks) { foreach ($action in @($task.Actions)) { $execute = [string]$action.Execute $arguments = [string]$action.Arguments if (-not $execute) { continue } $combined = "$execute $arguments" $reasons = @() if ($combined -match '(?i)(\\Temp\\|\\AppData\\Local\\Temp\\|\\Users\\Public\\|\\Windows\\Temp\\)') { $reasons += 'временный каталог' } if ($combined -match '(?i)(powershell|pwsh).*(-enc|-encodedcommand)') { $reasons += 'закодированная команда PowerShell' } if ($combined -match '(?i)(curl|wget|bitsadmin|certutil).*(http|ftp)') { $reasons += 'загрузка из сети' } if ($combined -match '(?i)\.(vbs|js|hta|bat|cmd)\b') { $reasons += 'скриптовый файл' } if ($reasons.Count -gt 0) { $results += [pscustomobject]@{ Task = $task.TaskName Path = $task.TaskPath State = [string]$task.State User = [string]$task.Principal.UserId Execute = $execute Arguments = $arguments Reasons = ($reasons -join '; ') } } if ($results.Count -ge $Max) { break } } if ($results.Count -ge $Max) { break } } if ($results.Count -eq 0) { Write-Host 'Подозрительных заданий не найдено.' exit 0 } $results | Format-Table Task, Path, State, User, Reasons -AutoSize Write-Host ("Найдено заданий: {0}" -f $results.Count) if ($Csv) { $results | Export-Csv -LiteralPath $Csv -NoTypeInformation -Encoding UTF8 Write-Host "CSV сохранён: $Csv" } exit 0