powershell - 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)
解决方案
如果您尝试执行位于远程计算机上的 PS1 脚本,就好像您在计算机本身上执行它一样,那么您可以通过 Remote Powershell 实现此目的。
https://4sysops.com/archives/use-powershell-invoke-command-to-run-scripts-on-remote-computers/
显然,这意味着脚本将在远程计算机上而不是您的计算机上执行操作(即读/写操作)。此外,远程计算机上必须允许远程连接(在 BIOS 设置中?)。
推荐阅读
- google-compute-engine - Compute Engine 虚拟机失去网络连接
- oauth-2.0 - 无法检索与 Azure AD 集成的 OAuth2 应用使用的授权类型
- mysql - SQL 查询仅返回 1 行,连接三个以上表的正确方法是什么?
- php - PHP 甲骨文数据库
- python - 如何分离 odes 系统的解的图
- sql - 从另一个没有子查询的表中更新具有第一个匹配行的表?
- android-10.0 - Android 11:范围存储权限,如何在外部存储和 SD 卡存储的根路径中创建新文件夹?
- java - 包内的公共类看不到公共接口?
- php - 如何使用函数的结果作为按钮的链接
- python - python pyzbar,FileNotFoundError:找不到模块