Hello guys,
is there a way to get an object of my Powershell Host? I want to open Sessions and send commands directly in my script without a workflow.
Something like this:
//modify properties
psHost.name = "myPSHost01";
psHost.transportProtocol = "HTTPS";
//invoke methods
psHost.openSession();
psHost.invokeScript(script);
psHost.closeSession(id);
With some research here i found this but i cannot use the output of this statement.
var psHosts = Server.findAllForType("PowerShell:PowerShellHost",null);
//com.vmware.o11n.plugin.powershell.scripting.PowerShellHost
for(psHost in psHosts) {
System.log(psHosts[psHost]);
}
Log:
[2016-11-14 14:17:49.306] [I] DynamicWrapper (Instance) : [PowerShellHost]-[class com.vmware.o11n.plugin.powershell.scripting.PowerShellHost] -- VALUE : com.vmware.o11n.plugin.powershell.scripting.PowerShellHost@3a5c781f
Does anyone of you know how the answer?
Thanks
Hi,
findAllForType() enumerates all object of a given type
var psHosts = Server.findAllForType("PowerShell:PowerShellHost",null);
for (psHost in psHosts) {
var pshostObj = psHosts[psHost]; // object of type PowerShellHost
var session = pshostObj.openSession();
}
In the above code, pshostObj is of type PowerShellHost, and you can use all its properties/methods like openSession(), etc.
Hi,
In your sample, is myPSHost01 one of the registered/configured PowerShell hosts, or you want to create a new temporary object on the fly without registering it?
If the latter, I think it is not possible with PS plug-in; only REST plug-in has something similar allowing creation of 'transient' host objects.
If the former, why can't you use the object(s) returned from findAllForType() ?
Hi,
myPSHost01 is one of the registered ones.
I cannot use findAllForType() because the properties and methods of a Powershell Host cannot be used which means i cannot even open a Session.
Hi,
findAllForType() enumerates all object of a given type
var psHosts = Server.findAllForType("PowerShell:PowerShellHost",null);
for (psHost in psHosts) {
var pshostObj = psHosts[psHost]; // object of type PowerShellHost
var session = pshostObj.openSession();
}
In the above code, pshostObj is of type PowerShellHost, and you can use all its properties/methods like openSession(), etc.
Thank you very much this worked for me.
Is there a way to pass a filter to findAllForType (XPath or OData?)
Wanted to search for a specific PS host without looping through the whole array.
PowerShellHostManager does not seem to have a search function
Thanks.
Support for XPath or OData filters/queries as a second argument to findAllForType() API is plug-in specific. That is, whatever expression/value you provide there will be passed to the plug-in, but the plug-in should contain some logic to actually parse this expression and utilize it during search.
The PowerShell plug-in does not implement such logic. It simply ignores the value passed as second argument to findallForType() call.
Thanks Ilian.