PowerShell invoke-command命令

PowerShell中的Invoke-Command cmdlet在本地和远程计算机上执行命令,并返回带有命令错误的输出。还可以在本地计算机上将此cmdlet作为命令用于脚本块。

语法

语法1:

Invoke-Command   
[-ScriptBlock] <scriptblock>   
[-NoNewScope]   
[-InputObject <psobject>]   
[-ArgumentList <Object[]>]  
[<CommonParameters>]

语法2:

Invoke-Command   
[[-Session] <PSSession[]>]   
[-FilePath] <string>   
[-ThrottleLimit <int>]   
[-AsJob]   
[-HideComputerName]  
[-JobName <string>]   
[-InputObject <psobject>]   
[-ArgumentList <Object[]>]    
[<CommonParameters>]

语法3:

Invoke-Command   
[[-Session] <PSSession[]>]   
[-ScriptBlock] <scriptblock>   
[-ThrottleLimit <int>]   
[-AsJob]  
[-HideComputerName]   
[-JobName <string>]   
[-InputObject <psobject>]  
[-ArgumentList <Object[]>]    
[<CommonParameters>]

语法4:

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>]

语法5:

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>]

语法6:

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>]

语法7:

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>]

语法8:

Invoke-Command   
[-VMId] <guid[]>   
[-ScriptBlock] <scriptblock>   
[-Credential <pscredential>]   
[-ConfigurationName <string>]   
[-ThrottleLimit <int>]   
[-AsJob]   
[-HideComputerName]   
[-InputObject <psobject>]   
[-ArgumentList <Object[]>]  
[<CommonParameters>]

语法9:

Invoke-Command   
[-VMId] <guid[]>   
[-FilePath] <string>   
-Credential <pscredential>   
[-ConfigurationName <string>]  
[-ThrottleLimit <int>]   
[-AsJob]   
[-HideComputerName]   
[-InputObject <psobject>]   
[-ArgumentList <Object[]>]  
[<CommonParameters>]

语法10:

Invoke-Command   
[-FilePath] <string>   
-Credential <pscredential>   
-VMName <string[]>   
[-ConfigurationName <string>]  
[-ThrottleLimit <int>]   
[-AsJob]   
[-HideComputerName]   
[-InputObject <psobject>]   
[-ArgumentList <Object[]>]  
[<CommonParameters>]

语法11:

Invoke-Command   
[-ScriptBlock] <scriptblock>  
 -ContainerId <string[]>   
[-ConfigurationName <string>]   
[-ThrottleLimit <int>]   
[-AsJob]   
[-HideComputerName]   
[-JobName <string>]   
[-RunAsAdministrator]   
[-InputObject <psobject>]  
[-ArgumentList <Object[]>]    
[<CommonParameters>]

语法12:

Invoke-Command   
[-FilePath] <string>  
-ContainerId <string[]>   
[-ConfigurationName <string>]   
[-ThrottleLimit <int>]  
[-AsJob]   
[-HideComputerName]   
[-JobName <string>]  
[-RunAsAdministrator]   
[-InputObject <psobject>]   
[-ArgumentList <Object[]>]    
[<CommonParameters>]

语法

-ScriptBlock - 此参数是必需的,它指定要执行的命令。 创建脚本块时,需要将命令括在大括号{}中。
-NoNewScope - 它是在PowerShell 3.0中引入的,标识此cmdlet在当前作用域中执行给定命令。 默认情况下,invoke-command在其范围内执行命令。
-InputObject - 此参数指定命令的输入。在命令中使用此参数时,需要在-ScriptBlock参数的值中使用$Input自动变量来表示输入对象。
-ArgumentList - 此参数按列出的顺序在命令中提供局部变量值。必须使用以下格式在命令中使用局部变量:

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

-Session - 此参数指定其中invoke-command在其中执行命令的会话的数组。
-FilePath - 此参数指定invoke-command在一台或多台远程计算机上执行的本地脚本的路径或文件名。 如果使用此参数,PowerShell会将给定脚本文件的内容转换为脚本块,然后将其传输到远程计算机以执行。
-ThrottleLimit - 此参数显示为执行invoke-command而建立的最大并发连接数。 它仅适用于当前命令,不适用于计算机或会话。
-AsJob - 如果使用此参数,则invoke-command将命令作为远程计算机上的后台作业执行。
-HideComputerName - 此参数从输出显示中省略每个对象的计算机名称。它不会更改对象,而只会影响输出显示。
-JobName - 此参数指定后台作业的友好名称。 在命令中使用此参数时,该命令将作为作业执行,并且Invoke-command返回作业的对象。
-ComputerName - 此参数指定在其上执行命令的计算机。 本地计算机是默认计算机。 当我们使用此参数时,PowerShell将创建一个临时连接,该临时连接仅用于执行命令。 如果需要永久连接,请使用-Session参数。
-Credential - 此参数允许用户帐户执行此操作。 默认值为当前用户。
-Port - Invoke-Command使用-Port参数来定义用于Invoke-Command的远程计算机上的网络端口。
-UseSSL - Invoke-Command使用-UseSSL参数使用SSL协议建立与远程计算机的连接。 这是一项附加保护,可通过HTTPS而不是HTTP发送数据。
-ConfigurationName - Invoke-Command使用-ConfigurationName参数来指定用于新PSSession的会话配置。
-ApplicationName - Invoke-Command使用此参数来标识连接URI应用程序的名称段。 如果未在命令中使用-ConnectionURI参数,请使用它。
-InDisconnectedSession - Invoke-command使用此参数在断开连接的会话中执行命令或脚本。 使用此参数时,invoke-command在每台远程计算机上创建永久会话,并启动-FilePath参数指定的命令,然后从该会话断开连接。
-SessionName - 此参数用于为断开连接的会话指定友好名称。 仅对-InDisconnectedSession参数有效。
-SessionOption - 此参数在此命令中用于指定会话的高级选项。
-Authentication - 此参数用于指定用于验证用户凭据的机制。 以下是此参数可接受的值:

  • Default
  • Kerberos
  • Negotiate
  • Basic
  • Digest
  • NegotiateWithImplicitCredential
  • Credssp

-EnableNetworkAccess - 此参数可以将交互安全性的令牌包括到回送会话中。
-CertificateThumbprint - 此参数用于指定有权连接到断开连接的会话的用户帐户的公钥证书。
-ConnectionUri - 此参数用于指定统一资源标识符(URI),该资源定义了会话的连接端点。 如果在命令中未指定ConnectionUri,请使用-Port-UseSSL参数指定连接URI的值。
-AllowRedirection - 此参数允许将此连接重定向到备用URI。当在命令中使用-ConnectionURI参数时,远程目标可以返回指令以重定向到其他URI。但是使用此参数允许它重定向连接。
-VMId - 在Invoke-Command中使用此参数来指定虚拟机ID的数组。
-VMName - 在Invoke-Command中使用此参数来指定虚拟机名称的数组。
-ContainerId - 此参数用于指定容器ID的数组。
-RunAsAdministrator - 在Invoke-Command中使用此参数以管理员身份调用命令。


上一篇:PowerShell get-command命令

下一篇:PowerShell get-help命令

关注微信小程序
程序员编程王-随时随地学编程

扫描二维码
程序员编程王

扫一扫关注最新编程教程