AWS Run PowerShell command

Hi Team : We have created new role and policy to utilise in Amazon Web Services Scope activity.

We are trying to run PowerShell command on EC2 instance and get services of different servers.

I have provided Commands as string and trying to provide instance details but argument takes values as UiPath.AmazonWebServices.Models.AWSEc2Instance (variable type).

For e.g. I have tried using below Vb script in invoke code Or assign activity but getting errors (compile errors etc)

Dim myInstance As New AWSEC2Instance()
myInstance.InstanceId = “i-1234567890abcdef0”

How to supply instance argument value to run PowerShell command?

To supply the instance argument value for running a PowerShell command on an EC2 instance using UiPath and the AWS SDK for .NET, you need to create an instance of the AWSEC2Instance class and assign the required properties. Here’s an example of how you can achieve this in VBScript:

Dim myInstance As New UiPath.AmazonWebServices.Models.AWSEC2Instance()
myInstance.InstanceId = "i-1234567890abcdef0"

' Convert the AWSEC2Instance object to a string in JSON format
Dim instanceJson As String = Newtonsoft.Json.JsonConvert.SerializeObject(myInstance)

' Pass the instance JSON as an argument to your PowerShell command
Dim powershellScript As String = "Your PowerShell command here -Instance " + instanceJson

' Execute the PowerShell script using the Invoke Power Shell activity or any other appropriate activity

In the above code, you create a new instance of AWSEC2Instance and assign the InstanceId property with the desired EC2 instance ID. Then, you convert the AWSEC2Instance object to a JSON string using Newtonsoft.Json.JsonConvert.SerializeObject(). Finally, you include the instance JSON as an argument to your PowerShell command, allowing you to pass the instance details to the command.

Make sure to replace "i-1234567890abcdef0" with the actual EC2 instance ID you want to target.