Hello,
I have been trying to come up with a workflow to run esxicli commands on an ESXi host, I am aware of the different solutions out there including the one that uses the vMA as an SSH server, but I would like to give it a try with the PowerShell plugin. So far I can connect to the vCenter, get the host and even get the esxcli object using the different examples already on the PowerShell plugin library.
But my problem is that after I get the esxcli object it is on the PowerShellRemotePSObject format and I don't know how to work with it.
var sess; try { sess = host.openSession() sess.addCommandFromString("Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue"); var invResult = sess.invokePipeline(); //Show result System.log( invResult.getHostOutput() ); sess.addCommandFromString('Connect-VIServer '+vcenter+' -User user@domain -Password "passw0rd" -Force'); var invResult = sess.invokePipeline(); //Show result System.log( invResult.getHostOutput() ); // Get PowerShellRemotePSObject sess.addCommandFromString('Get-VMHost -Name '+esxi+' -Server '+vcenter); var invResult = sess.invokePipeline(); //Show result System.log( invResult.getHostOutput() ); var psObject = invResult.getResults(); if (invResult.invocationState == 'Failed'){ System.error(invResult.getErrors()); } else { var cmd = sess.addCommandFromString('Get-EsxCli') cmd.addParameter('Server', vcenter); cmd.addParameter('VMHost', psObject); var sessionId = sess.getSessionId(); var esxcli = System.getModule("com.vmware.library.powershell").invokeCommand(host,sessionId); System.log(esxcli); } } catch ( ex ) { System.log (ex); } finally { if (sess) { host.closeSession( sess.getSessionId()); } }
Given the esxcli object is accessed for instance like $esxcli.software.vib.list() in PowerShell I don't know how to use the PowerShellPSObject to access the information or execute methods on it.
Any help is appreciated.
Thank you,
Juan.