-1

我有一个由 PLC 触发的 PowerShell v1 脚本。它应该将文件从嵌入式 PC 的桌面复制到网络路径。

如果我手动运行脚本,它工作得很好,但如果脚本是由 PLC 触发的,我会收到以下错误:

    + CategoryInfo : NotSpecified: (:) [Copy-Item], IOException
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand
copy-item : 用户名或密码不正确。

任何提示,为什么我会收到此错误,将不胜感激!

4

1 回答 1

-1

感谢您的帮助@TheIncorrigible1 阅读您的评论后,我发现了问题!

问题是,由 plc 启动的脚本与手动启动的脚本以外的另一个用户一起运行。

所以解决方法是首先使用另一个脚本使用正确的凭据启动 powershell。例如像这样:

$usr = 'XXX'

$paswrd = 'XXX'

$securePassword = ConvertTo-SecureString $paswrd -AsPlainText -Force

$credential = 新对象 System.Management.Automation.PSCredential $usr, $securePassword

$args = "/你的脚本的路径"

启动进程 powershell.exe -Credential $credential -ArgumentList ("-file $args")

缺点...纯文本密码...

于 2017-12-19T07:41:50.270 回答