Copy-Item to networkpath:用户名或密码不正确

问题描述 投票:-1回答:1

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

如果我手动运行脚本它工作正常,但如果脚本由PLC触发,我将收到以下错误:

    + CategoryInfo          : NotSpecified: (:) [Copy-Item], IOException
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand
copy-item : The user name or password is incorrect.

任何提示,为什么我收到此错误,将非常感谢!

powershell copy-item network-shares
1个回答
0
投票

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

问题是,plc启动的脚本与另一个用户运行而不是手动启动的脚本。

因此,解决方法是首先使用另一个脚本使用正确的凭据启动PowerShell。例如:

$ usr ='XXX'

$ password ='XXX'

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

$ credential = New-Object System.Management.Automation.PSCredential $ usr,$ securePassword

$ args =“/脚本路径”

Start-Process powershell.exe -Credential $ credential -ArgumentList(“ - file $ args”)

缺点...明文密码......

© www.soinside.com 2019 - 2024. All rights reserved.