PowerShell修改task schedule

1.Get-command -moudle  scheduledTask

2.get-

3.set-scheduledtask

Set-ScheduledTask
   [[-Password] <String>]
   [[-User] <String>]
   [[-Action] <CimInstance[]>]
   [[-TaskPath] <String>]
   [[-Settings] <CimInstance>]
   [[-Trigger] <CimInstance[]>]
   [-TaskName] <String>
   [-CimSession <CimSession[]>]
   [-ThrottleLimit <Int32>]
   [-AsJob]
   [<CommonParameters>]

 地址:Set-ScheduledTask (ScheduledTasks) | Microsoft Docs

4.添加一个task

$action_console="D:\ConsoleDemo\ConsoleTest\ConsoleTest\bin\Debug\netcoreapp3.1\ConsoleTest.exe"
$TaskName = "powershellTask"
$UserName ="namedemo"
$UserPass="psw"
$sset_n = New-ScheduledTaskSettingsSet -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries
$action_n = New-ScheduledTaskAction -Execute $action_console
$trigger_n = New-ScheduledTaskTrigger -AtLogOn
$task_n = New-ScheduledTask -Action $action_n -Trigger $trigger_n -Settings $sset_n
Register-ScheduledTask $TaskName -InputObject $task_n -User $UserName -Password $UserPass -Force

 5.查询  

参考地址:schtasks change | Microsoft Docs

schtasks /query /S remoteServer /tn TestChangePassword /v  /fo list
schtasks /query /S binglsedevbox  /U useraccount  /P pwd  /v  /fo list
/tn taskname 
/S Specifies the name or IP address of a remote computer (with or without backslashes). The default is the local computer
/v advanced settings

 6.修改密码

Set-ScheduledTask -TaskName "powershellTask"   -Password "password" -User "username"

 

posted @ 2021-07-14 18:10  留下成长的足迹  阅读(299)  评论(0编辑  收藏  举报