首页 > 解决方案 > Powershell - 如何运行位于另一台计算机上的脚本?

问题描述

谁能给我一些提示?我被这个问题困住了。

我开发了一个 PowerShell 脚本,位于:

\\\ComputerNameA.xxx.xxx.local\d\xxx\script.ps1

该脚本需要 4 个参数才能工作。我需要从另一台计算机运行该脚本。

我努力了:

Invoke-Command -ComputerName ComputerNameA 
      -FilePath \\\ComputerNameA.xxx.xxx.local\d\xxx\script.ps1  
      -ArgumentList {-arg0 string -arg1 string -arg2 string -arg3 string}

任何提示将不胜感激。

更新:至于回答我原来的问题,我认为答案是: Invoke-Command -ComputerName ComputerNameA -Credential $cred -FilePath \\ComputerNameA.xxx.xxx.local\d\xxx\script.ps1
-ArgumentList {-arg0 string -arg1 字符串 -arg2 字符串 -arg3 字符串}

现在,新问题是即使存在凭据,我也收到拒绝访问错误(即我设置了一个新用户帐户 - abcd 并将密码设置为 abcd)

标签: powershell

解决方案


如果您尝试执行位于远程计算机上的 PS1 脚本,就好像您在计算机本身上执行它一样,那么您可以通过 Remote Powershell 实现此目的。

https://4sysops.com/archives/use-powershell-invoke-command-to-run-scripts-on-remote-computers/

显然,这意味着脚本将在远程计算机上而不是您的计算机上执行操作(即读/写操作)。此外,远程计算机上必须允许远程连接(在 BIOS 设置中?)。


推荐阅读