TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

PowerShell Invoke-Command

PowerShell Invoke-Command with What is PowerShell, History of PowerShell, Features of PowerShell, PowerShell vs CMD, PowerShell Scripting, PowerShell Versions, PowerShell Commands, PowerShell Looping, PowerShell Conditions, PowerShell Array, PowerShell Brackets etc.

<< Back to POWERSHELL

PowerShell Invoke-Command

The Invoke-Command cmdlet in PowerShell executes commands on local and remote computers and returns the output with the errors from the command.

We can also use this cmdlet on the local computers to the script blocks as a command.

Syntax

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

Parameters

-ScriptBlock

This parameter is required, and it specifies the command to execute. When we create a script block, we need to enclose the commands in curly braces {}.

-NoNewScope

It was introduced in PowerShell 3.0 and identifies that this cmdlet executes the given command in the current scope. By default, invoke-command executes the commands in their scope.

-InputObject

This parameter specifies the input to the command. When we use this parameter in the command, we need to use the $Input automatic variable in the value of the -ScriptBlock parameter to denote the input objects.

-ArgumentList

This parameter supplies the local variable values in the command in the same order as they are listed. You must use the following format to use the local variable in the command:

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

-Session

This parameter specifies the array of sessions in which the invoke-command executes the command.

-FilePath

This parameter specifies the path or the file name of the local script that the invoke-command executes on one or more remote computers. If you use this parameter, PowerShell converts the content of the given script file to a script block and then transmits it to the remote computer for execution.

-ThrottleLimit

This parameter shows you a maximum number of concurrent connections which are established to execute the invoke-command. It applies only to the current command, not to the computer or to the session.

-AsJob

If you use this parameter, the invoke-command executes the commands as a background job on a remote computer.

-HideComputerName

This parameter omits the computer name of each object from the output display. It does not change the object but affects only the output display.

-JobName

This parameter specifies the friendly name for the background job. When this parameter is used in a command, the command is executed as a job, and Invoke-command returns an object of job.

-ComputerName

This parameter specifies the computers on which the command executes. The local computer is the default. When we use this parameter, PowerShell creates a temporary connection which is used only to execute the commands. If you need a permanent connection, use the -Session parameter.

-Credential

This parameter permits the user account to perform this action. The default is the current user.

-Port

The Invoke-Command uses -Port parameter to define the network ports on a remote computer, which is used for the Invoke-Command.

-UseSSL

The Invoke-Command uses -UseSSL parameter to establish a connection to the remote computer using the SSL protocol. It is an additional protection which sends the data across an HTTPS instead of HTTP.

-ConfigurationName

The Invoke-Command uses -ConfigurationName parameter to specify a session configuration which is used for the new PSSession.

-ApplicationName

The Invoke-command uses this parameter to identify the name segment of the application of the connection URI. If you are not using the -ConnectionURI parameter in the command, then use it.

-InDisconnectedSession

The Invoke-command uses this parameter to execute the command or a script in a disconnected session. When you use this parameter, the invoke-command creates the permanent session on each remote computer and starts the command specified by the -FilePath parameter, and after then disconnects from the session.

-SessionName

This parameter is used to specify a friendly name for a disconnected session. It is only valid with the -InDisconnectedSession parameter.

-SessionOption

The -SessionOption parameter is used in this command to specify the advance option for the session.

-Authentication

This parameter is used to specify the mechanism which is used to authenticate the credentials of a user. Following are the acceptable values for this parameter:

  • Default (It is a default value)
  • Kerberos
  • Negotiate
  • Basic
  • Digest
  • NegotiateWithImplicitCredential
  • Credssp

-EnableNetworkAccess

The use of this parameter in this cmdlet to include the tokens of interactive security to the loopback sessions.

-CertificateThumbprint

This parameter is used to specify the public key certificate of a user account which has permission to connect to the disconnected session.

-ConnectionUri

This parameter is used to specify the Uniform Resource Identifier (URI), which defines the connection endpoints of the session. If the ConnectionUri is not specified in the command, use the -Port and UseSSL parameters to specify the values of connection URI.

-AllowRedirection

This parameter allows redirection of this connection to an alternate URI. When we use the -ConnectionURI parameter in the command, then the remote destination can return the instructions to redirect to different URI. But we use this parameter to allow it to redirect the connection.

-VMId

This parameter is used in the Invoke-Command to specify an array of IDs of the virtual machines.

-VMName

This parameter is used in theInvoke-Command to specify an array of names of the virtual machines.

-ContainerId

This parameter is used to specify the array of container IDs.

-RunAsAdministrator

This parameter is used in the Invoke-Command to invoke the command as an administrator.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf