Created
June 5, 2024 08:49
-
-
Save othmanalikhan/6b79899ee8458bacc2ca66d55aece664 to your computer and use it in GitHub Desktop.
Pentest Utility: Find Scheduled Tasks on Windows Created by Users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get a list of built-in accounts | |
$builtInAccounts = @( | |
"Administrator", | |
"DefaultAccount", | |
"Guest", | |
"SYSTEM", | |
"LOCAL SERVICE", | |
"NETWORK SERVICE" | |
) | |
# Get all scheduled tasks | |
$tasks = Get-ScheduledTask | |
# Filter tasks by checking the author | |
$userTasks = foreach ($task in $tasks) { | |
$taskDetails = Get-ScheduledTaskInfo -TaskName $task.TaskName -TaskPath $task.TaskPath | |
$taskAuthor = $task.Principal.UserId | |
# Check if the author is not a built-in account | |
if ($taskAuthor -and $builtInAccounts -notcontains $taskAuthor) { | |
[PSCustomObject]@{ | |
TaskName = $task.TaskName | |
TaskPath = $task.TaskPath | |
Author = $task.Principal.UserId | |
Description = $task.Description | |
LastRunTime = (Get-ScheduledTaskInfo -TaskName $task.TaskName -TaskPath $task.TaskPath).LastRunTime | |
NextRunTime = $task.NextRunTime | |
Status = (Get-ScheduledTaskInfo -TaskName $task.TaskName -TaskPath $task.TaskPath).TaskState | |
Actions = $task.Actions | ForEach-Object { | |
[PSCustomObject]@{ | |
Type = $_.ActionType | |
Path = $_.Execute | |
Arguments = $_.Arguments | |
WorkingDir = $_.WorkingDirectory | |
} | |
} | |
} | |
} | |
} | |
# Display the tasks created by users | |
$userTasks | Format-Table -AutoSize | |
$userTasks | Format-List |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment