VMware Cloud Community
fmateo
Hot Shot
Hot Shot

Reading PowerShellRemotePSObjects

Hello,

I'm trying to read this objects types from vCO PowerShell plugin.  I try to pass this obects between "Scriptable Task".

I try to execute an external PowerShell Script from the default workflow provided by the plugin.  This is the code:

var output;
var session;
try {
    session = host.openSession();
    var script =  '& "' + externalScript + '" ' + arguments;
    output = System.getModule("com.vmware.library.powershell").invokeScript(host,script,session.getSessionId()) ;
} finally {
    if (session){
        host.closeSession(session.getSessionId());
    }
}

And then i try to read the outoput variable as a PowerShellRemotePSObject type on another "Scriptable Task".

I read on vmware vco PS plugin, that I can use the functions:  getXml(), or getRootObject(), and getAsJson(), but any of these returns me anyting.

The other thing is that I don't know how can I read it Smiley Happy

The external script, on a powershell windows returns me a value, the value that I need.

Does anyone, that can help with this little problem?

Thank you very much

Best Regards,

Francesc

Reply
0 Kudos
4 Replies
igaydajiev
VMware Employee
VMware Employee

There is a sample workflow distributed together with the plug-in demonstrating how you can work with result objects returned from PowerShell script invocation. It can be found in "Library/PowerShell/Samples/List directory content".

If you want to pass result betwean scripting block, you will need to use the same PowerShell session.

What you need to do is :

1. Prepare your own workfow

2. Add openSession action. preserve the returned sessionId in WF attribute

3. Add invokeScript action ( providing the session id). Eventualy preserve the result from execution in attribute

4. now you can work with the result until the session is closed

5. Add closeSession action

For more complete example take a look of "Library/PowerShell/Sample/Toggle virtual machine state" workflow. This workflow uses  pregenerated actions from cmdlets, but they can be replaced with invokeScript

Hope it helps.

Reply
0 Kudos
fmateo
Hot Shot
Hot Shot

Ok, I will try Smiley Wink

I write the result later,

thanks

Reply
0 Kudos
fmateo
Hot Shot
Hot Shot

Hello,

Finally I rewrite the script code.  I change the line:

output = System.getModule("com.vmware.library.powershell").invokeScript(host,script,session.getSessionId()) ;

by this one:

output = session.invokeScript(script), where script is the ps1 script that work in PS window.

Now I can read the output variable as a PSObject, with getResults() function, or getHostOutput(), that is the output I want.

At this moment is the only thing I need Smiley Happy

Thank you,

Best Regards

Reply
0 Kudos
igaydajiev
VMware Employee
VMware Employee

Perfect ...

Reply
0 Kudos