- Print
- DarkLight
- PDF
Invoke-CUAction: Run an Action
- Print
- DarkLight
- PDF
Introduction
With the Invoke-CUAction
cmdlet, you can run an action as you would do from the Real-Time DX Console or in the VDI App.
Syntax
Invoke-CUAction [-ActionId] <string> [-Table] <string> [[-UserInput] <string>] [-RecordsGuids] <string[]> [<CommonParameters>]
How to run
- Import the ControlUp.PowerShell.User module into your PowerShell session
$pathtomodule = (Get-ChildItem "C:\Program Files\Smart-X\ControlUpMonitor\*ControlUp.PowerShell.User.dll" -Recurse | Sort-Object LastWriteTime -Descending)[0]
Import-Module $pathtomodule
- Execute the cmdlet by providing the required input parameters to trigger a specific operation on a particular item, such as user sessions, machines, processes, and so on.
Invoke-CUAction -ActionId b636f434-2843-4a5c-a21a-eed7a02d0946 -RecordsGuids e99b0de6-2b0f-495a-ba0e-3d1c1dfe88d9 -Table Sessions
Input parameters
Property | Description | Type |
---|---|---|
ActionID | The ID of the action. You can retrieve this action by issuing the Get-CUAvailableActions cmdlet | String |
Table | The table property of the action, see property table of the output section | String |
UserInput | The user input of the action | String |
RecordGuids | The user input of the action | String[] |
Output
Property | Description | Type |
---|---|---|
Id | Internal ID | String |
RequestId | Internal use. Each action that is invoked gets its own Request ID | String |
OperationId | Same as RequestID | String |
UpdateTime | The timestamp of the message | Decimal |
SubjectId | Shows the RecordGUID (as specified in the script input parameter "RecordsGuids" | String |
SubjectDescriptive | Shows record information | String |
IsAdvanced | Internal use | String |
RecordId | Same as SubjectId | String |
Started | Indicates if the action was started | Boolean |
RecordDescriptive | Shows record information | String |
NodeId | The internal ID of the monitor node | String |
RequestingMonitor | Shows the monitor from which the PowerShell cmdlet was executed | String |
Location | On which machine was the action executed | String |
Result | Shows the result of the action. Possible values are: "None", "Success", "Warning", "CompleteWithError", or "Error" | String |
Output | Shows the action output | String |
ErrorMessage | Shows the execution context | String |
ErrorCode | Error Code (see section below) | Integer |
Timeout | If action runs into a timeout, it is shown here | String |
How to run
In this example, we show you how to run the Analyze Logon Duration script on a user session.
Retrieve the ActionID and the Table.
$actions = Get-CUAvailableActions $ALD = $actions | Where-Object {$_.Title -eq 'Analyze Logon Duration'} | select-object Id, Title, Table
You can see that the ALD script needs to run on a user session. To get session information, we make use of the
Invoke-CUQuery
cmdlet which is a powerful method to retrieve real-time information from the monitor's in-memory database.(Invoke-CUQuery -Scheme Main -Table Sessions -fields sUserAccount, eConnectState, sServerName -TranslateEnums -Where "sUserAccount = '[domain]\[username]'" -sort eConnectState).Data
Now, let's grab this sessionID and assign it to the $ALD variable and add it as a property
$userSession = (Invoke-CUQuery -Scheme Main -Table Sessions -fields sUserAccount, eConnectState, sServerName -TranslateEnums -Where "sUserAccount = '[domain]\[username]'" -sort eConnectState).Data $userSession.key
The ALD script requires input parameters which we need to provide to the Invoke-CUAction cmdlet. To collect all input parameters for the ALD script, we can use the
Get-CUActionSignature
cmdlet.Get-CUActionSignature -ActionId $ALD.Id
Now we have all input parameters for the
Invoke-CUAction
cmdlet. Let's run the action:
Invoke-CUAction -ActionId b636f434-2843-4a5c-a21a-eed7a02d0946 -RecordsGuids db421154-361e-4054-85f6-bcdbd23c7b43 -Table Sessions -UserInput '"{\"arg_0\":\"-DomainUser\",\"arg_2\":\"-CUDesktopLoadTime\",\"arg_4\":\"-SessionId\",\"arg_6\":\"-SessionName\",\"arg_8\":\"-ClientName\"}"'
Error codes
Below, you can find the API error code that is returned for each request. If the returned error code is 0, it indicates that the action was successfully executed.
Error Code | Description |
---|---|
1001 | Instruction Not Found |
1002 | Record Not Found |
1003 | Invalid Certificate |
1004 | Invalid Signature |
1005 | Invalid Request |
1006 | Invalid Request Time |
1010 | Failed Resolving Credentials From Cache |
1011 | Credential Key Not Found |
1021 | Instruction Denied |
1022 | Local Admin Denied |
1023 | User Denied |
1024 | Permission Error |
1030 | Monitor Not Found |
1040 | Internal Error |
1041 | Failed To Execute |
1042 | No action to execute |
1043 | Invalid entity type for this instruction |
1044 | Error occurs on create action |
1045 | Argument missing |
1046 | Duplicated action |
1047 | Invalid entity for this instruction |
Examples
Example 1 - Run an action that requires user credentials
For some actions, you need to provide user credentials that are stored in your Credentials Store.
Get the ActionID with the
Get-CUAvailableActions
cmdletUse the
Get-CUCredentials
cmdlet to retrieve the key of the shared credential
Use the
Get-CUComputers
cmdlet to retrieve the ID of the machine on which the action should run. In our example, we run the Get Citrix Connection Failures action which needs to run on a Citrix Delivery Controller.Get-CUComputers | where {$_.FQDN -eq 'CUXENDDC-19A.controlUp.demo'}
Retrieve the input parameters for the action
Get-CUActionSignature -ActionId c65e3712-2c27-4bf5-a08b-686d48da5b0b
As you can see, this action has two input parameters:
Replace the default value "1" with "2" and run the action
Invoke-CUAction -ActionId "c65e3712-2c27-4bf5-a08b-686d48da5b0b" -Table "Computers" -RecordsGuids "63e8be03-595b-4b6b-8eba-4faee44045ec" -UserInput '"{\"arg_1\":\"2\", \"creds\": { \"saved\" : true, \"user\" : \"\", \"domain\" : \"\", \"cypher\" : \"\", \"monitor\" : \"\", \"keyId\" : \"dede1f6f-490b-4b97-b9c9-99799021494b\", \"publicKey\" : \"\"}}"'