I have several hundred scheduled tasks. Im looking for a way to get the name of the task that called a powershell script when the script has been executed by the task scheduler. So for instance I could include that name in an alert I am sending so we know not only which server but which specific task
You can use the get-scheduledtask
cmdlet. You find this cmdlet in the ScheduledTasks
module.
Each returned task has an Actions Property.
Eg
(Get-ScheduledTask)[0].Actions
To add on to Peter Schneider helpful answer which will give you details on the first task in the list. So, more specifically, to get them all, try this...
(((Get-ScheduledTask).Actions) | Select-Object *) -match 'powershell' | Select-Object -Property Id,Execute,Arguments | Format-Table -Wrap
Id Execute Arguments
-- ------- ---------
StartPowerShellJob powershell.exe -NoLogo -NonInteractive -WindowStyle Hidden -Command "Import-Module PSScheduledJob; …
Note, the '*' gest all properties and you may not want to do that, so, just explicitly select the ones you'd want
(((Get-ScheduledTask).Actions) | Select-Object -Property Id,Execute,Arguments) -match 'powershell' | Format-Table -Wrap
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.