I have created a workflow which task is to mainly deploy a new VM from a template and perform sysprep, add more ram (if requested), more cpu (again if requested), more disks etc etc. The workflow has a custom script part generating a random password (string) and the "run program in guest" is then used to call "net user administrator <random pw>" which sets the random password on the deployed VM. An email is then sent to the requestor with information that the VM is deployed and what password was assigned. The workflow works as a charm.
But now I need to run another "run program in guest" workflow (the last task of the workflow), but this is not working as the deployed VM no longer has the default template password. I have to supply this workflow with the new random password which was created - but this is not working either, because the "run program in guest" workflow requires password as securestring, but my random password is generated in string-format (obviously as It has to be set with "net user" and readable in email. And I can't bind this stringvariable to the securestring input as a quick workaround using visible binding.....
The solution would be an easy scriptable task with the vmRandomPassword as input, and vmSecureRandomPassword as output and then a scriptcode converting input string to output securestring.... But I can't get this to work, and everything I google seem to be powershell - but I can't use powershell syntax in vCO either....
So either bind the scirptable task where you generate the password to a securestring workflow attribute, or add an additional scriptable element that takes a normal string normalPassword as in and the secureString securePassword as out and just do a
securePassword = normalPassword;
in the script.
I can't actually verify if this works, because there seems to be another problem. Since the "Run Program in Guest" doesn't wait for the "program" to actually finish, and continues the workflow in a fraction of a second, the next workflow seems to try executing before the script setting the password has actually finished, causing the workflow to fail because the random password is not yet in action.....
Is there som way to initiate a WAIT for given number of seconds?
yep, that's intentionally, runProgramInGuest is ansynchronous.
To wait for just a few seconds, use System.sleep(timeInMilliseconds), for longer breaks use the wait-for-date element (see an example here: How to deal with long running external processes | VMware vCenter Orchestrator Blog - VMware Blogs )