windows task

Win+R and typing taskschd.msc

schtasks.exe

/Create Add a new scheduled task
/tn Name of task
/sc schedule frequency (MINUTE, HOURLY, DAILY and so on)
/d On which day or day of month the task shall be scheduled. You can use * for scheduling on every day
/st Start time in format HH:mm
/tr Application to run, e.g. cmd.exe

schtasks.exe /create /tn my-task /sc daily  /st 13:00 /tr cmd.exe

pwsh

$action = New-ScheduledTaskAction -Execute 'cmd.exe'
$trigger = New-ScheduledTaskTrigger -Daily -At 14:00
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "my-task2"
Unregister-ScheduledTask -TaskName
# Use the Get-ScheduledTask to get task details
$task = Get-ScheduledTask | Where-Object {$_.TaskName -eq "Remove Log File Task"} | Select-Object -First 1
if($task -ne $null){
   Unregister-ScheduledTask $task.TaskName -Confirm:$false
}
else {
   Write-Host "Scheduled task doesn't exist."
}
Get-ScheduledTask

Get-ScheduledTask -TaskPath "\" | Disable-ScheduledTask

Get-ScheduledTask | Where {$_.TaskName -eq "UserAccountTests"} | Disable-ScheduledTask

Get-ScheduledTask | Where {$_.TaskName -eq "UserAccountTests"} | Select State

Get-ScheduledTask | Where {$_.TaskName -eq "UserAccountTests"}

https://shellgeek.com/

posted @ 2023-05-12 17:37  fndefbwefsowpvqfx  阅读(26)  评论(0编辑  收藏  举报