个性化阅读
专注于IT技术分析

PowerShell Invoke Command调用命令

PowerShell中的Invoke-Command cmdlet在本地和远程计算机上执行命令, 并返回带有命令错误的输出。

我们还可以在本地计算机上将此cmdlet作为命令用于脚本块。

句法

Invoke-Command 
[-ScriptBlock] <scriptblock> 
[-NoNewScope] 
[-InputObject <psobject>] 
[-ArgumentList <Object[]>]
[<CommonParameters>]
Invoke-Command 
[[-Session] <PSSession[]>] 
[-FilePath] <string> 
[-ThrottleLimit <int>] 
[-AsJob] 
[-HideComputerName]
[-JobName <string>] 
[-InputObject <psobject>] 
[-ArgumentList <Object[]>]  
[<CommonParameters>]
Invoke-Command 
[[-Session] <PSSession[]>] 
[-ScriptBlock] <scriptblock> 
[-ThrottleLimit <int>] 
[-AsJob]
[-HideComputerName] 
[-JobName <string>] 
[-InputObject <psobject>]
[-ArgumentList <Object[]>]  
[<CommonParameters>]
Invoke-Command 
[[-ComputerName] <string[]>] 
[-ScriptBlock] <scriptblock> 
[-Credential <pscredential>] 
[-Port <int>] 
[-UseSSL] 
[-ConfigurationName <string>] 
[-ApplicationName <string>] 
[-ThrottleLimit <int>] 
[-AsJob]
[-InDisconnectedSession] 
[-SessionName <string[]>] 
[-HideComputerName] 
[-JobName <string>] 
[-SessionOption <PSSessionOption>] 
[-Authentication {Default | Basic |Negotiate|NegotiateWithImplicitCredential | Credssp |Digest | Kerberos}] 
[-EnableNetworkAccess] 
[-InputObject <psobject>] 
[-ArgumentList <Object[]>]
[-CertificateThumbprint <string>]  
[<CommonParameters>]
Invoke-Command
[[-ComputerName] <string[]>] 
[-FilePath] <string> 
[-Credential <pscredential>] 
[-Port <int>]
[-UseSSL] 
[-ConfigurationName <string>] 
[-ApplicationName <string>] 
[-ThrottleLimit <int>] 
[-AsJob]
[-InDisconnectedSession] 
[-SessionName <string[]>] 
[-HideComputerName] 
[-JobName <string>] 
[-SessionOption <PSSessionOption>] 
[-Authentication {Default | Basic | Negotiate | NegotiateWithImplicitCredential | Credssp | Digest | Kerberos}] 
[-EnableNetworkAccess] 
[-InputObject <psobject>] 
[-ArgumentList <Object[]>]
[<CommonParameters>]
Invoke-Command 
[[-ConnectionUri] <uri[]>] 
[-ScriptBlock] <scriptblock> 
[-Credential <pscredential>]
[-ConfigurationName <string>] 
[-ThrottleLimit <int>] 
[-AsJob] 
[-InDisconnectedSession] 
[-HideComputerName]
[-JobName <string>]
[-AllowRedirection] 
[-SessionOption <PSSessionOption>] 
[-Authentication {Default | Basic | Negotiate | NegotiateWithImplicitCredential | Credssp | Digest | Kerberos}] [-EnableNetworkAccess] [-InputObject <psobject>] 
[-ArgumentList <Object[]>] 
[-CertificateThumbprint <string>]  
[<CommonParameters>]
Invoke-Command 
[[-ConnectionUri] <uri[]>] 
[-FilePath] <string> 
[-Credential <pscredential>] 
[-ConfigurationName <string>] 
[-ThrottleLimit <int>] 
[-AsJob] 
[-InDisconnectedSession] 
[-HideComputerName] 
[-JobName <string>]
[-AllowRedirection] 
[-SessionOption <PSSessionOption>] 
[-Authentication {Default | Basic|Negotiate| NegotiateWithImplicitCredential| Credssp | Digest | Kerberos}] 
[-EnableNetworkAccess] 
[-InputObject <psobject>]
[-ArgumentList <Object[]>]  
[<CommonParameters>]
Invoke-Command 
[-VMId] <guid[]> 
[-ScriptBlock] <scriptblock> 
[-Credential <pscredential>] 
[-ConfigurationName <string>] 
[-ThrottleLimit <int>] 
[-AsJob] 
[-HideComputerName] 
[-InputObject <psobject>] 
[-ArgumentList <Object[]>]
[<CommonParameters>]
Invoke-Command 
[-VMId] <guid[]> 
[-FilePath] <string> 
-Credential <pscredential> 
[-ConfigurationName <string>]
[-ThrottleLimit <int>] 
[-AsJob] 
[-HideComputerName] 
[-InputObject <psobject>] 
[-ArgumentList <Object[]>]
[<CommonParameters>]
Invoke-Command 
[-FilePath] <string> 
-Credential <pscredential> 
-VMName <string[]> 
[-ConfigurationName <string>]
[-ThrottleLimit <int>] 
[-AsJob] 
[-HideComputerName] 
[-InputObject <psobject>] 
[-ArgumentList <Object[]>]
[<CommonParameters>]
Invoke-Command 
[-ScriptBlock] <scriptblock>
 -ContainerId <string[]> 
[-ConfigurationName <string>] 
[-ThrottleLimit <int>] 
[-AsJob] 
[-HideComputerName] 
[-JobName <string>] 
[-RunAsAdministrator] 
[-InputObject <psobject>]
[-ArgumentList <Object[]>]  
[<CommonParameters>]
Invoke-Command 
[-FilePath] <string>
-ContainerId <string[]> 
[-ConfigurationName <string>] 
[-ThrottleLimit <int>]
[-AsJob] 
[-HideComputerName] 
[-JobName <string>]
[-RunAsAdministrator] 
[-InputObject <psobject>] 
[-ArgumentList <Object[]>]  
[<CommonParameters>]

参数

-脚本块

此参数是必需的, 它指定要执行的命令。创建脚本块时, 需要将命令括在大括号{}中。

-NoNewScope

它是在PowerShell 3.0中引入的, 标识此cmdlet在当前范围内执行给定命令。默认情况下, invoke-command在其范围内执行命令。

-InputObject

此参数指定命令的输入。在命令中使用此参数时, 需要在-ScriptBlock参数的值中使用$ Input自动变量表示输入对象。

-ArgumentList

此参数按列出的顺序在命令中提供局部变量值。你必须使用以下格式在命令中使用局部变量:

{param($<name1>[, $<name2>]...) <command-with-local-variables>} -ArgumentList <value> -or- <local-variable>

-会议

此参数指定其中invoke-command在其中执行命令的会话的数组。

-文件路径

此参数指定invoke-command在一台或多台远程计算机上执行的本地脚本的路径或文件名。如果使用此参数, PowerShell会将给定脚本文件的内容转换为脚本块, 然后将其传输到远程计算机以执行。

-油门限制

此参数显示为执行invoke-command而建立的最大并发连接数。它仅适用于当前命令, 不适用于计算机或会话。

-AsJob

如果使用此参数, 则invoke-command将命令作为远程计算机上的后台作业执行。

-HideComputerName

此参数从输出显示中省略每个对象的计算机名称。它不会更改对象, 而只会影响输出显示。

-工作名称

此参数指定后台作业的友好名称。在命令中使用此参数时, 该命令将作为作业执行, 并且Invoke-command返回作业的对象。

-计算机名

此参数指定在其上执行命令的计算机。本地计算机是默认计算机。当我们使用此参数时, PowerShell将创建一个临时连接, 该临时连接仅用于执行命令。如果需要永久连接, 请使用-Session参数。

-凭据

此参数允许用户帐户执行此操作。默认值为当前用户。

-港口

Invoke-Command使用-Port参数来定义用于Invoke-Command的远程计算机上的网络端口。

-使用SSL

Invoke-Command使用-UseSSL参数使用SSL协议建立与远程计算机的连接。这是一项附加保护, 可通过HTTPS而不是HTTP发送数据。

-ConfigurationName

Invoke-Command使用-Co​​nfigurationName参数来指定用于新PSSession的会话配置。

-应用名称

Invoke-命令使用此参数来标识连接URI应用程序的名称段。如果未在命令中使用-Co​​nnectionURI参数, 请使用它。

-InDisconnectedSession

Invoke-command使用此参数在断开连接的会话中执行命令或脚本。使用此参数时, invoke-command在每台远程计算机上创建永久会话, 并启动-FilePath参数指定的命令, 然后从该会话断开连接。

-SessionName

此参数用于为断开连接的会话指定友好名称。仅对-InDisconnectedSession参数有效。

-SessionOption

-SessionOption参数在此命令中用于指定会话的高级选项。

-认证

此参数用于指定用于验证用户凭据的机制。以下是此参数可接受的值:

  • 默认值(默认值)
  • 的Kerberos
  • 谈判
  • 基本的
  • 消化
  • 隐含协商凭证
  • Credssp

-启用网络访问

在此cmdlet中使用此参数可以将交互安全性的令牌包括到回送会话中。

-证书缩略图

此参数用于指定有权连接到断开连接的会话的用户帐户的公钥证书。

-ConnectionUri

此参数用于指定统一资源标识符(URI), 该资源定义了会话的连接端点。如果在命令中未指定ConnectionUri, 请使用-Port和UseSSL参数指定连接URI的值。

-AllowRedirection

此参数允许将此连接重定向到备用URI。当我们在命令中使用-Co​​nnectionURI参数时, 远程目标可以返回指令以重定向到其他URI。但是我们使用此参数允许它重定向连接。

-VMId

在Invoke-Command中使用此参数来指定虚拟机ID的数组。

-VMName

在Invoke-Command中使用此参数来指定虚拟机名称的数组。

-ContainerId

此参数用于指定容器ID的数组。

-以管理员身份运行

在Invoke-Command中使用此参数以管理员身份调用命令。


赞(0)
未经允许不得转载:srcmini » PowerShell Invoke Command调用命令

评论 抢沙发

评论前必须登录!