更新子文件夹中的计划任务(指定路径无效.)PowerShell 4.0 [英] Update Scheduled Task in Sub Folder (The Specified path is invalid.) PowerShell 4.0

查看:52
本文介绍了更新子文件夹中的计划任务(指定路径无效.)PowerShell 4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行下面的脚本时出现以下错误:Set-ScheduledTask : The specified path is invalid.

When running the script below I get the following error: Set-ScheduledTask : The specified path is invalid.

$Action = New-ScheduledTaskAction -Execute """C:\Program Files\Sync\Sync.exe""" -Argument "C:\ProgramData\Sync\Script.bat"
Set-ScheduledTask  -TaskName "Task Name" -TaskPath "\SFTP Schedules\Non-Live\" -Action $Action

这是文件夹结构.

任务计划程序文件夹

有人知道为什么吗?

推荐答案

只要您的帐户在服务器上的管理员组中,您的代码就可以,即使您不是作者,您也应该能够更改任务.还要确保您以管理员身份运行 PowerShell 控制台.

Your code is fine as long as your account is in the administrator group on the server, you should be able to change the Task even if your not the author. Also make sure that you are running your PowerShell console as Administrator.

但如果您不是 runAs 用户,那么您将需要提供该用户的凭据才能编辑任务.

But if you are not the runAs user then you will need to supply the credentials of that user to be able to edit the Task.

Set-ScheduledTask -Password "password" -User "Domain\User" -TaskName "name" -TaskPath ... 

如果要将计划任务文件夹中的所有任务导出到XML,然后替换XML中的作者,您可以使用以下代码.更改 $_.TaskPath -eq '\' 以匹配您要导出的文件夹.

If you want to export all the task in a scheduled task folder to XML and then replace the author in the XML you can you the following code. Change $_.TaskPath -eq '\' to match the folder you want to export.

$XMLDestFolder = "C:\XML\"
Get-ScheduledTask | ?{$_.TaskPath -eq '\'} | %{
    $TaskXML = Export-ScheduledTask -TaskName $_.TaskName
    $TaskXML -replace "(?<=<Author>).*?(?=</Author>)","ADFP\NETMANFP" > "$XMLDestFolder$($_.TaskName).xml" 
} 

这篇关于更新子文件夹中的计划任务(指定路径无效.)PowerShell 4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆