VMware Cloud Community
mannu07
Contributor
Contributor

Parsing the PowershellRemoteObject output in VRO

Hi,

I'm trying to execute an external powershell script, that returns the following output in powershell console. I need this same output to be received in VRO. When I run the workflow. Execution is successful, but the output PSRemote object is null. I'm not finding the output in logs too. How do I pass this output to VRO?

Methods tried:

- Taking this entire output as a single array of strings in powershell before returning to VRO.

- Using getResults(),getHostOutput(),getRootObject() methods.

Still I'm not able to parse this output in VRO.

Please help me out with this issue.

                     

psoutput.png

Thanks,

Mano

Tags (1)
Reply
0 Kudos
4 Replies
igaydajiev
VMware Employee
VMware Employee

There are sample workflow distirubted with PowerShell plugin taht can be found in "Library/Power Shell/Samples". One of the sample workflows is "List directory content" . You can take a look at it for an example how to work with powershell output. Worklfow can be found in

Could you provide your PS script?

Reply
0 Kudos
DHSR
Contributor
Contributor

When working with Powershell I like to use the Guest Script Manager package available here:

FlowGrab: View Project

This will store the output in a variable which you can parse or manipulate

mannu07
Contributor
Contributor

Hi,

Here is the snippet from the code of how it returns the output...

oo.png

Thanks,

Mano

Reply
0 Kudos
igaydajiev
VMware Employee
VMware Employee

No need to parse manually the ouptut. This is handled by PowerShell plugin itself.

I am attaching a sample workflow. Workflow will list first tree running processes on PSHost machine and store the result in $objects variable. Then it will retun it to to vRO.


list first tree running processes on PSHost machine.

>$objects = get-process | Select-Object -first 3

and then return them to vRO

>$objects

Then you can use PowerShell plugin scripting API to extract given property values

First get acces to root result object (in our case it is list of processes)

>        var psList = psObject.getRootObject();

Then we iterate over each process and return their name and path

>System.log( item.getProperty('Name') );

To see what properties are avaialvbe you can either check microsoft documentation regarding particular type. or print row JSON/XML replresentaiton of the returned objects

PS : Note that using Format-List will returne new objects (with different type)  and not the original one

Reply
0 Kudos