我创建了一个 New-SchedukedTask。当我尝试取消注册它时,我遇到了以下错误。我是 powershell 新手。请帮帮我。
PS C:\> $taskAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-File "C:\DevToolSetup.ps1"'
>> $now_time = Get-Date
>> $curent_time = $now_time.AddSeconds(15)
>> $taskTrigger = New-ScheduledTaskTrigger -At $curent_time -Once
>> $taskName = "GithubAutomation"
>> $description = "Github Configurations Automation"
>> Register-ScheduledTask -TaskName $taskName -Action $taskAction -Trigger $taskTrigger -Description $description -RunLevel Highest
TaskPath TaskName State
-------- -------- -----
\ GithubAutomation Ready
PS C:\>
PS C:\> Unregister-ScheduledTask -TaskName 'GithubAutomation' -Confirm:$false
Unregister-ScheduledTask : The system cannot find the file specified.
At line:1 char:1
+ Unregister-ScheduledTask -TaskName 'GithubAutomation' -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (MSFT_ScheduledTask:Root/Microsoft/...T_ScheduledTask) [Unregister-ScheduledTask], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070002,Unregister-ScheduledTask
PS C:\>
答案1
你错过了-TaskPath
争论。
答案2
这是一个老问题,但我刚刚遇到了同样的问题。当我以管理员权限运行 power shell 窗口时,一切正常。在这种情况下,错误消息“找不到指定的文件”具有误导性。