更新记录
转载请注明出处。
2022年8月25日 发布。
2022年8月18日 从笔记迁移到博客。
实例:
$taskAction = New-ScheduledTaskAction -Execute pwsh.exe `
-Argument 'Write-Host "hello world"'
$taskTrigger = New-ScheduledTaskTrigger -Daily `
-At '00:00:00'
Register-ScheduledTask -TaskName 'TaskName' `
-Action $taskAction `
-Trigger $taskTrigger `
-RunLevel 'Limited' `
-Description 'This line is too long to read'
使用splatting把参数分割出来
$newTaskAction = @{
Execute = 'pwsh.exe'
Argument = 'Write-Host "hello world"'
}
$newTaskTrigger = @{
Daily = $true
At = '00:00:00'
}
$registerTask = @{
TaskName = 'TaskName'
Action = New-ScheduledTaskAction @newTaskAction
Trigger = New-ScheduledTaskTrigger @newTaskTrigger
RunLevel = 'Limited'
Description = 'Splatting is easy to read'
}
Register-ScheduledTask @registerTask
标签:00,Task,newTaskAction,Schedule,Execute,ScheduledTask,New,TaskName,PowerShell
From: https://www.cnblogs.com/cqpanda/p/16589988.html