[英]Powershell - how to run a script located on another computer?
Could anyone please offer me some hints?谁能给我一些提示? I am stuck with this problem.我被这个问题困住了。
I have developed a PowerShell script located in:我开发了一个 PowerShell 脚本,位于:
\\\ComputerNameA.xxx.xxx.local\d\xxx\script.ps1
This script requires 4 arguments to work.该脚本需要 4 个 arguments 才能工作。 I need to run that script from another computer.我需要从另一台计算机运行该脚本。
I have tried:我努力了:
Invoke-Command -ComputerName ComputerNameA
-FilePath \\\ComputerNameA.xxx.xxx.local\d\xxx\script.ps1
-ArgumentList {-arg0 string -arg1 string -arg2 string -arg3 string}
Any hints will be appreciated.任何提示将不胜感激。
Update: As to answer my original question, I think the answer is: Invoke-Command -ComputerName ComputerNameA -Credential $cred -FilePath \\ComputerNameA.xxx.xxx.local\d\xxx\script.ps1更新:至于回答我原来的问题,我认为答案是:Invoke-Command -ComputerName ComputerNameA -Credential $cred -FilePath \\ComputerNameA.xxx.xxx.local\d\xxx\script.ps1
-ArgumentList {-arg0 string -arg1 string -arg2 string -arg3 string} -ArgumentList {-arg0 字符串 -arg1 字符串 -arg2 字符串 -arg3 字符串}
Now, the new problem is I got the access denied error even the credential is exist (ie I setup a new user account - abcd and set the password as abcd)现在,新问题是即使存在凭据,我也收到拒绝访问错误(即我设置了一个新用户帐户 - abcd 并将密码设置为 abcd)
If you try to execute a PS1 script located on a remote computer as if you do it physically on the computer itself, then you can achieve this via Remote Powershell.如果您尝试执行位于远程计算机上的 PS1 脚本,就好像您在计算机本身上执行它一样,那么您可以通过 Remote Powershell 实现此目的。
https://4sysops.com/archives/use-powershell-invoke-command-to-run-scripts-on-remote-computers/ https://4sysops.com/archives/use-powershell-invoke-command-to-run-scripts-on-remote-computers/
Obviously, it implies that the script will do things (ie read/write operations) on the remote computer instead of yours.显然,这意味着脚本将在远程计算机上而不是您的计算机上执行操作(即读/写操作)。 Also, remote connection (in the BIOS settings?) must be allowed on the remote computer.此外,远程计算机上必须允许远程连接(在 BIOS 设置中?)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.