Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scanner 'Get-ScheduledTaskActions' to get more info about Scheduled Tasks #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<#
.SYNOPSIS
PDQ Inventory Scanner to retrieve Scheduled Tasks including action(s)

.PARAMETER TaskName
Specifies an array of one or more names of a scheduled task. You can use "*" for a wildcard character query.

.PARAMETER TaskPath
Specifies an array of one or more paths for scheduled tasks in Task Scheduler namespace. You can use "*" for a wildcard character query.
You can use \* for the root folder. To specify a full TaskPath you need to include the leading and trailing \.

.INPUTS
None. You can't pipe objects.

.OUTPUTS
System.Management.Automation.PSCustomObject.
Get-ScheduledTasksActions.ps1 returns a PSCustomObject each action within a scheduled task.
Note that a single Scheduled Tasks can have multiple actions.

.LINK
Parameters TaskName and TaskPath are the same as the built-in cmdlet `Get-ScheduledTask`

.EXAMPLE
PS> .\Get-ScheduledTasksActions.ps1 -TaskName "Microsoft*"
TaskName : Microsoft Compatibility Appraiser
TaskPath : \Microsoft\Windows\Application Experience\
TaskActionExe : %windir%\system32\compattelrunner.exe
[...]

#>
param (
[PSDefaultValue(Help = "Wildcard filter, display all Scheduled Tasks by name")]
[SupportsWildcards()]
[string[]]$TaskName = "*",
[PSDefaultValue(Help = "Wildcard filter, display all Scheduled Tasks by path")]
[SupportsWildcards()]
[string[]]$TaskPath = "\*"
)

$tasks = Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -ErrorAction SilentlyContinue

if (!$tasks) {
throw "No scheduled tasks found"
}

foreach ($task in $tasks) {
foreach ($action in $task.Actions) {
[PSCustomObject]@{
TaskName = $task.TaskName
TaskPath = $task.TaskPath
TaskURI = $task.URI
TaskAuthor = $task.Author
TaskRunAsUser = $task.Principal.UserId
TaskEnabled = $task.Settings.Enabled
TaskHidden = $task.Settings.Hidden
TaskActionExe = $action.Execute
TaskActionArgs = $action.Arguments
TaskActionWorkDir = $action.WorkingDirectory
}
}
}
16 changes: 16 additions & 0 deletions PowerShell Scanners/Get-ScheduledTasksActions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Instructions
[How to use this repository](../../README.md)

# Description
Retrieve Scheduled Tasks including action(s). Tasks can be filtered by TaskName and TaskPath.
Run `Get-Help Get-ScheduledTasksActions.ps1` for more information and examples.

# Parameters
## TaskName
Specifies an array of one or more names of a scheduled task. You can use "*" for a wildcard character query.

## TaskPath
Specifies an array of one or more paths for scheduled tasks in Task Scheduler namespace. You can use "*" for a wildcard character query. You can use \* for the root folder. To specify a full TaskPath you need to include the leading and trailing \.

# Author
David Bekker
29 changes: 29 additions & 0 deletions PowerShell Scanners/Get-ScheduledTasksActions/Scan Profile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<AdminArsenal.Export Code="PDQInventory" Name="PDQ Inventory" Version="19.3.30.0" MinimumVersion="19.0">
<ScanProfile>
<Collections type="list" />
<Scanners type="list">
<Scanner>
<ModifiedDate>2024-11-18T13:52:01.7672096+01:00</ModifiedDate>
<Name>Get-ScheduledTasksActions</Name>
<UID>4614b4ed4b734b14bb32b15df48937d4</UID>
<Script>
</Script>
<FileName>C:\PowerShell-Scanners\PowerShell Scanners\Get-ScheduledTasksActions\Get-ScheduledTasksActions.ps1</FileName>
<Parameters>
</Parameters>
<AdditionalFiles>
</AdditionalFiles>
<RowLimit value="100" />
<TypeName>PowerShell</TypeName>
<SourceScannerId value="90" />
</Scanner>
</Scanners>
<Description>Retrieve Scheduled Tasks including action(s)</Description>
<ScanProfileId value="33" />
<Name>PS - Get-ScheduledTasksActions</Name>
<ScheduleTriggerSet name="ScheduleTriggers">
<Triggers type="list" />
</ScheduleTriggerSet>
</ScanProfile>
</AdminArsenal.Export>