Running commands in local and remote systems have different methods. We can use psexec
, commands own feature or Invoke-Command
cmdlet. In this tutorial we will look how to use Invoke-Command
in powershell. Invoke-Command
runs commands remotely and returns the output like success or error messages.
在本地和远程系统中运行命令有不同的方法。 我们可以使用psexec
,命令自己的功能或Invoke-Command
cmdlet。 在本教程中,我们将研究如何在Powershell中使用Invoke-Command
。 Invoke-Command
远程运行命令,并返回输出(如成功或错误消息)。
帮帮我 (Help)
Detailed help about the Invoke-Command
can be get like below.
有关Invoke-Command
详细帮助可以从下面获得。
PS> Run Powershell Script On Remote Computer
Also more detailed help can be get by adding -full
option like below. This will provide enormous output and provide help like parameters details, usage examples etc.
通过添加如下所示的-full
选项,也可以获得更详细的帮助。 这将提供巨大的输出,并提供诸如参数详细信息,用法示例等帮助。
PS> Get-Help Invoke-Command -full
启用PSRemoting(Enable PSRemoting)
In order to run Powershell command on the remote systems the remote systems should be configured to accept remote powershell commands via PSRemoting
. Following post shows how to enable PSRemoting in windows operating systems.
为了在远程系统上运行Powershell命令,应该将远程系统配置为通过PSRemoting
接受远程Powershell命令。 以下文章显示了如何在Windows操作系统中启用PSRemoting。
How To Enable Powershell Remoting PSRemoting or WinRM?
如何启用Powershell Remoting PSRemoting或WinRM?
在远程计算机上运行命令 (Run Command On Remote Computer)
One of the most used example of Invoke-Command
is running command on remote systems. We will specify following parameters to run command remotely.
最常用的Invoke-Command
示例之一是在远程系统上运行命令。 我们将指定以下参数以远程运行命令。
-ComputerName
specifies the host name or IP address of the remote system-ComputerName
指定远程系统的主机名或IP地址Credentials
specifies the remote system login user with domain or comp