Matan Issler
Matan Issler

Reputation: 29

Getting Scheduled Tasks Between Specific Times On Windows 10 Desktop

I'm having some troubles using the PowerShell in windows 10 in order to get specific scheduled tasks. I need to get a list of scheduled task that run between 9:00 PM to 12 PM. I couldn’t figure out how to use the “Get-ScheduledTask “ and “Get-ScheduledTaskInfo” commands properly. I will be so grateful if someone can help me writing the script the right way!

Upvotes: 1

Views: 1954

Answers (2)

Esperento57
Esperento57

Reputation: 17462

Other method, give you all necessary infos :

Get-ScheduledTask| %{$taskName=$_.TaskName; $_.Triggers | 
where {$_ -ne $null -and $_.Enabled -eq $true -and $_.StartBoundary -ne $null -and ([System.DateTime]$_.StartBoundary).Hour -in 21..23} |  %{ 
[pscustomobject]@{
Name=$taskName; 
trigger=$_
Enabled=$_.Enabled
EndBoundary=$_.EndBoundary
ExecutionTimeLimit=$_.ExecutionTimeLimit
Id=$_.Id
Repetition=$_.Repetition
StartBoundary=$_.StartBoundary
DaysInterval=$_.DaysInterval
RandomDelay=$_.RandomDelay
PSComputerName=$_.PSComputerName
}

}

} 

Upvotes: 0

Mark Wragg
Mark Wragg

Reputation: 23355

I think this is what you need:

Get-ScheduledTask | ForEach-Object {
    $NextRunTimeHour = ($_ | Get-ScheduledTaskInfo).NextRunTime.Hour
    If ($NextRunTimeHour -in 21..23) { $_ }
}

Gets the Scheduled Tasks, then iterates through them with ForEach-Object, piping each to Get-ScheduledTaskInfo to get the .NextRunTime property and it's .Hour subproperty and then returning the Scheduled task if the hour is 21, 22 or 23.

Upvotes: 3

Related Questions