< Back
Invoke-ControlCommand
Post
NAME Invoke-ControlCommand
SYNOPSIS
Will issue a command against a given machine and return the results.
SYNTAX
Invoke-ControlCommand [-SessionID] <Guid[]> [[-Command] <String>] [[-TimeOut] <Int32>] [[-MaxLength] <Int32>]
[-PowerShell] [[-OfflineAction] <Object>] [[-BatchSize] <Int32>] [<CommonParameters>]
DESCRIPTION
Will issue a command against a given machine and return the results.
PARAMETERS
-SessionID <Guid[]>
The GUID identifier for the machine you wish to connect to.
You can retrieve session info with the 'Get-ControlSessions' commandlet
SessionIDs can be provided via the pipeline.
IE - Get-AutomateComputer -ComputerID 5 | Get-ControlSessions | Invoke-ControlCommand -Powershell -Command
"Get-Service"
Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false
-Command <String>
The command you wish to issue to the machine.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-TimeOut <Int32>
The amount of time in milliseconds that a command can execute. The default is 10000 milliseconds.
Required? false
Position? 3
Default value 10000
Accept pipeline input? false
Accept wildcard characters? false
-MaxLength <Int32>
The maximum number of bytes to return from the remote session. The default is 5000 bytes.
Required? false
Position? 4
Default value 5000
Accept pipeline input? false
Accept wildcard characters? false
-PowerShell [<SwitchParameter>]
Issues the command in a powershell session.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-OfflineAction <Object>
Required? false
Position? 5
Default value Wait
Accept pipeline input? false
Accept wildcard characters? false
-BatchSize <Int32>
Number of control sessions to invoke commands in parallel.
Required? false
Position? 6
Default value 20
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
The output of the Command provided.
NOTES
Version: 2.2
Author: Chris Taylor
Modified By: Gavin Stone
Modified By: Darren White
Creation Date: 1/20/2016
Purpose/Change: Initial script development
Update Date: 2019-02-19
Author: Darren White
Purpose/Change: Enable Pipeline support. Enable processing using Automate Control Extension. The cached APIKey
will be used if present.
Update Date: 2019-02-23
Author: Darren White
Purpose/Change: Enable command batching against multiple sessions. Added OfflineAction parameter.
Update Date: 2019-06-24
Author: Darren White
Purpose/Change: Updates to process object returned by Get-ControlSessions
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Get-AutomateComputer -ComputerID 5 | Get-AutomateControlInfo | Invoke-ControlCommand -Powershell -Command
"Get-Service"
Will retrieve Computer Information from Automate, Get ControlSession data and merge with the input object, then
call Get-Service on the computer.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Invoke-ControlCommand -SessionID $SessionID -Command 'hostname'
Will return the hostname of the machine.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Invoke-ControlCommand -SessionID $SessionID -TimeOut 120000 -Command 'iwr -UseBasicParsing
"https://bit.ly/ltposh" | iex; Restart-LTService' -PowerShell
Will restart the Automate agent on the target machine.
RELATED LINKS
SYNOPSIS
Will issue a command against a given machine and return the results.
SYNTAX
Invoke-ControlCommand [-SessionID] <Guid[]> [[-Command] <String>] [[-TimeOut] <Int32>] [[-MaxLength] <Int32>]
[-PowerShell] [[-OfflineAction] <Object>] [[-BatchSize] <Int32>] [<CommonParameters>]
DESCRIPTION
Will issue a command against a given machine and return the results.
PARAMETERS
-SessionID <Guid[]>
The GUID identifier for the machine you wish to connect to.
You can retrieve session info with the 'Get-ControlSessions' commandlet
SessionIDs can be provided via the pipeline.
IE - Get-AutomateComputer -ComputerID 5 | Get-ControlSessions | Invoke-ControlCommand -Powershell -Command
"Get-Service"
Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false
-Command <String>
The command you wish to issue to the machine.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-TimeOut <Int32>
The amount of time in milliseconds that a command can execute. The default is 10000 milliseconds.
Required? false
Position? 3
Default value 10000
Accept pipeline input? false
Accept wildcard characters? false
-MaxLength <Int32>
The maximum number of bytes to return from the remote session. The default is 5000 bytes.
Required? false
Position? 4
Default value 5000
Accept pipeline input? false
Accept wildcard characters? false
-PowerShell [<SwitchParameter>]
Issues the command in a powershell session.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-OfflineAction <Object>
Required? false
Position? 5
Default value Wait
Accept pipeline input? false
Accept wildcard characters? false
-BatchSize <Int32>
Number of control sessions to invoke commands in parallel.
Required? false
Position? 6
Default value 20
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
The output of the Command provided.
NOTES
Version: 2.2
Author: Chris Taylor
Modified By: Gavin Stone
Modified By: Darren White
Creation Date: 1/20/2016
Purpose/Change: Initial script development
Update Date: 2019-02-19
Author: Darren White
Purpose/Change: Enable Pipeline support. Enable processing using Automate Control Extension. The cached APIKey
will be used if present.
Update Date: 2019-02-23
Author: Darren White
Purpose/Change: Enable command batching against multiple sessions. Added OfflineAction parameter.
Update Date: 2019-06-24
Author: Darren White
Purpose/Change: Updates to process object returned by Get-ControlSessions
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Get-AutomateComputer -ComputerID 5 | Get-AutomateControlInfo | Invoke-ControlCommand -Powershell -Command
"Get-Service"
Will retrieve Computer Information from Automate, Get ControlSession data and merge with the input object, then
call Get-Service on the computer.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Invoke-ControlCommand -SessionID $SessionID -Command 'hostname'
Will return the hostname of the machine.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Invoke-ControlCommand -SessionID $SessionID -TimeOut 120000 -Command 'iwr -UseBasicParsing
"https://bit.ly/ltposh" | iex; Restart-LTService' -PowerShell
Will restart the Automate agent on the target machine.
RELATED LINKS