在一台计算机上使用 Powershell 在另一台计算机上执行 Powershell 脚本 [英] Using Powershell on one computer to execute a Powershell script on another

查看:79
本文介绍了在一台计算机上使用 Powershell 在另一台计算机上执行 Powershell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能真的很明显,因为我是 Powershell 的新手,但是在访问另一台计算机以在该计算机上运行 Powershell 脚本的一台计算机上运行 Powershell 脚本的最佳方法是什么?如果重要的话,我正在使用 V2.0.

This might be really obvious, since I'm kind of new to Powershell, but what's the best way to run a Powershell script on one computer that accesses another to run a Powershell script on that one? I'm using V2.0 if that matters.

推荐答案

首先,您需要在远程计算机上启用远程计算机.登录到该计算机并从提升的(管理员)提示中执行:

First you will need to enable remoting computer on the remote computer. Log onto that computer and from an elevated (admin) prompt execute:

Enable-PSRemoting -Force

然后您可以使用 Invoke-Command 在远程计算机上运行命令.在脚本的情况下,您可能希望为远程计算机创建一个新的 pssession (New-PSSession),然后使用该会话作为 Invoke-Command 的参数调用命令,例如:

Then you can use Invoke-Command to run commands on the remote computer. In the case of a script, you probably want to create a new pssession (New-PSSession) to the remote computer and then invoke commands using that session as a parameter to Invoke-Command e.g.:

$s = new-PSSession -computername (import-csv servers.csv) `
                   -credential domain01\admin01 -throttlelimit 16
invoke-command -session $s -scriptblock {get-process powershell} -AsJob

请注意,您需要在提升的(管理员)提示下运行才能使用远程处理基础结构.查看这两个 cmdlet 的帮助以了解更多详细信息以及 about_remote 主题 (man about_remote).

Note that you will need to run in an elevated (admin) prompt to be able to use the remoting infrastructure. Look at the help on these two cmdlets for more details as well as the about_remote topic (man about_remote).

这篇关于在一台计算机上使用 Powershell 在另一台计算机上执行 Powershell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆