VMware Cloud Community
ananddp
Contributor
Contributor

Convert javascript datatype value

Comparison of value fails, because datatype value returned by invoke powershell script is a function. Is there a way to get them converted to string value

currentAutoAdminLogin = System.getModule("com.vmware.library.powershell").invokeScript(psHost,script1,sessionId);

returns value 0 in orchestrator output window

var stdAutoAdminLogin = "0"


System.log(currentAutoAdminLogin)

[2015-12-24 12:58:23.837] [I] DynamicWrapper (Instance) : [PowerShellRemotePSObject]-[class com.vmware.o11n.plugin.powershell.model.RemotePSObject] -- VALUE : com.vmware.o11n.plugin.powershell.model.RemotePSObject@2c47da58

System.log( typeof(currentAutoAdminLogin)

[2015-12-24 12:58:23.837] [I] function


System.log(currentAutoAdminLogin == 0)

[2015-12-24 13:10:36.135] [I] false

Reply
0 Kudos
3 Replies
SpasKaloferov
VMware Employee
VMware Employee

Hi,

What is the PS script you are invoking ? What i usually do is to convert the output to JSON and work with it.

Best Regards / Поздрави

Spas Kaloferov | Technical Solutions

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

vRO scripting objects are not 'real' Javascript objects but some sort of wrappers. That's why typeof() returns function. It's not an error; this is the expected behavior.

invokeScript() call returns an object of type PowerShellRemotePSObject. Check vRO API Explorer for what you can do with objects of this type - you can get it in JSON format, in XML format, or as a vRO object.

In your case, I would start with retrieving the 'proper' result using something like the following:

    var obj = currentAutoAdminLogin.getRootObject();

   System.log( obj );

Reply
0 Kudos
ananddp
Contributor
Contributor

SpasKaloferov & Ilian Iliev: Thanks for your response.

Actually i am trying to get a registry value of a remote computer using the invoke script and i want to return the value as string so that i can compare with a standard value.

Reply
0 Kudos