简体   繁体   English

Powershell - 如何运行位于另一台计算机上的脚本?

[英]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 设置中?)。

You can try installing ssh server where the scripts is located then connect using putty for windows您可以尝试安装脚本所在的 ssh 服务器,然后使用腻子连接 windows
then execute refer to this然后执行参考这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用PowerShell脚本在远程计算机上运行另一个PowerShell脚本 - How to use a PowerShell script to run another PowerShell Script on a Remote Computer 从另一台计算机运行时,powershell获取计算机名称,脚本位于哪里 - powershell get computer name where is script located when running from another computer 如何在远程计算机上运行 PowerShell 脚本? - How to run PowerShell script on a remote computer? 如何将参数传递到Powershell脚本并在远程计算机上运行 - how to pass parameters to Powershell script and run it on a remote computer 如何为计算机上的所有用户帐户运行PowerShell脚本? - How to run a PowerShell script for all user accounts on a computer? 我应该如何在远程计算机上运行 Powershell 脚本? - How should I run a Powershell script on a remote computer? 如何在具有域用户凭据的本地计算机上运行Powershell脚本 - How to run Powershell script on local computer but with credentials of a domain user 如何将PowerShell脚本从计算机运行到不受信任的域? - How to run PowerShell script from a computer to untrusted domain? 如何在计算机启动时运行Powershell脚本 - How to run powershell script on computer start-up 如何在计算机启动时运行 PowerShell 脚本? - How do I run a PowerShell script when the computer starts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM