11

I've downloaded the powershell script located here: http://gallery.technet.microsoft.com/scriptcenter/Get-Scheduled-tasks-from-3a377294

However, this doesn't give me the piece of info I'm looking for. i want to see if any task is set to wake the pc in order to run that task. I see where in the script it's looping through and displaying the properties for each task. But I'm not familiar with working with powershell or the Schedule.Service object so i don't know what property that is. Could someone eithe tell me a way to get a list of tasks set to wake the pc? or just tell me how to edit that script so it displays that bit of info.

thanks

merk
  • 1,721
  • 5
  • 23
  • 39
  • See one of my earlier answers: http://stackoverflow.com/questions/15439542/how-to-use-powershell-to-inventory-scheduled-tasks @mjolinor's xml-path should work, but my example will show you how to get the object(and xml-property) with COM if you don't have the `Get-ScheduledTask` cmdlet available. That cmdlet is only available in Win8/2012 and above. – Frode F. Dec 11 '13 at 21:58
  • For the pc i want to run this on, it's running windows 8.1 – merk Dec 12 '13 at 22:15
  • Okey, then you won't even need the powerpack @mjolinor suggested. Get-ScheudledTask is `built-in`. For future question, you could specify that. Unless tagged or in description, we assume PowerShell 2.0 on winXP + :-) – Frode F. Dec 13 '13 at 05:49
  • @merk I suggest updating this to mark [Dan's 1-liner answer](https://stackoverflow.com/a/29590919/28411) as accepted – RJFalconer May 21 '20 at 21:41

4 Answers4

20

This can be done in a one-liner:

Get-ScheduledTask | where {$_.settings.waketorun}

Get-ScheduledTask is available in Windows 8.1, Windows PowerShell 4.0, Windows Server 2012 R2.

Dan Rice
  • 620
  • 5
  • 6
4

on win8.1:

$tasks = Get-ScheduledTask

ForEach ($task in $tasks)
{
    if($task.settings.waketorun -eq 'True')
        {"$($task.taskname)"}
}
pwrsh3ll
  • 41
  • 2
3

That information should be down in the xml. Edit: Graimer is correct that this is not using the same script that was linked.
This uses Get-ScheduledTask from the TaskScheduler Module in the PowerShellPack, which can be downloade from here: http://archive.msdn.microsoft.com/PowerShellPack

$tasks = Get-ScheduledTask -ComputerName <ComputerName>

ForEach ($task in $tasks)
 {
   $xml = [xml]$task.xml
   if ($xml.task.settings.waketorun -eq 'True')
     { "Task $($task.name) is set to WakeToRun" }
 } 

or simply

 Get-ScheduledTask | select TaskName,TaskPath,@{name="Aufweckung.";expression={$_.Settings.WakeToRun}} -ExpandProperty Triggers | ft -AutoSize -Wrap
Michael Teper
  • 4,591
  • 2
  • 32
  • 49
mjolinor
  • 66,130
  • 7
  • 114
  • 135
  • `Get-ScheduledTask` is a Windows 8+ exclusive cmdlet. If you're talking about a 3rd party cmdlet, please link to the script/module. Your solution will not work the script provided by @merk – Frode F. Dec 11 '13 at 21:54
  • You are correct. I've provided a link to the source (MSDN PowerShellPack). There are also some other useful modules included. – mjolinor Dec 11 '13 at 22:09
  • Thank you - this will be used on a Windows 8.1 machine so i should be good. I'll try this later when i get home. Could you tell me where i can look up the available properties for a task? I tried doing some msdn googling wasn't able to find all the properties available for a task. – merk Dec 12 '13 at 22:17
  • Do a get-task | fomrat-list * on a single known task. The will show you all the avaiable information for that task. – mjolinor Dec 12 '13 at 22:25
1

You can get a bit more info which enables you to find it in the task scheduler with this:

$tasks = Get-ScheduledTask

ForEach ($task in $tasks)
{
    if($task.settings.waketorun -eq 'True')
        {"$($task)"}
}
Steve
  • 11
  • 1
  • I'm using this lines, to turn off all wakeup settings: $tasks = Get-ScheduledTask $task.settings.WakeToRun = $false Set-ScheduledTask -TaskName $task.TaskName -TaskPath $task.TaskPath -Settings $task.Settings – AlfeG Jul 02 '15 at 05:28
  • To improve a little on AlfeG's code; this lists the WakeToRun tasks: `Get-ScheduledTask |? { $_.Settings.WakeToRun }` -- and this turns that "feature" off: `Get-ScheduledTask |? { $_.Settings.WakeToRun } |% { $_.Settings.WakeToRun = $false ; Set-ScheduledTask -TaskName $_.TaskName -TaskPath $_.TaskPath -Settings $_.Settings }`. Here's hoping this prevents some more laptops from overheating in their bags... – j0057 Jun 23 '17 at 19:09
  • j0057 really nails the Get-/Set-ScheduledTask in his comment. – Jari Turkia Dec 17 '17 at 11:08