VMware Cloud Community
DexG83
Enthusiast
Enthusiast
Jump to solution

How to parse the "Invoke an external script" result >> PowerShellRemotePSObject

Hello Community,

I have a problem understanding the return object type of a external powershell script call.

From the Invoke an external script Workflow I get back a PowerShell:PowerShellRemotePSObject result.

I need to parse the result to reuse the data from the Script execution. In nearly 90% the following scriptable task will do the job:

if (psResult.invocationState  == 'Failed'){

    System.error(invResult.getErrors());

} else {

    dataFromResult = psResult.getRootObject();

    for each (key in dataFromResult.keys) {

            System.debug(key + " = " + dataFromResult.get(key));

    }

}

but unfortunately when more than one action is done in the powershell script I get back a result object with kind of nested objects and I don't really know how to unpack them.

I'm really looking forward to read some ideas.

Kind Regards,

Dex

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Documentation says that the result of PowerShellRemotePSObject#getRootObject() call can be simple type, ArrayList, Properties or PowerShellPSObject.

So you need to add some checks for the type of your dataFromResult variable and process it accordingly, for example something like:

if (dataFromResult instanceof Properties) {

  // handle as Properties

} else if (dataFromResult instanceof Array) {

  // handle as Array

} else if (dataFromResult instanceof PowerShellPSObject) {

  // handle as PowerShellPSObject

} else {

  // handle as simple type

}

(your current code seems to assume that dataFromResult is always of type Properties).

View solution in original post

Reply
0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Documentation says that the result of PowerShellRemotePSObject#getRootObject() call can be simple type, ArrayList, Properties or PowerShellPSObject.

So you need to add some checks for the type of your dataFromResult variable and process it accordingly, for example something like:

if (dataFromResult instanceof Properties) {

  // handle as Properties

} else if (dataFromResult instanceof Array) {

  // handle as Array

} else if (dataFromResult instanceof PowerShellPSObject) {

  // handle as PowerShellPSObject

} else {

  // handle as simple type

}

(your current code seems to assume that dataFromResult is always of type Properties).

Reply
0 Kudos
DexG83
Enthusiast
Enthusiast
Jump to solution

Hi Ilian,

I tested a bit around and your Solution is exactly what I was looking for!

Thank you very much for your fast reply.

Kind Regards,
Dex

Reply
0 Kudos