VMware Cloud Community
JoJoGabor
Expert
Expert

Powershell Workflow doesnt work when part of a larger workflow

I have a small workflow which runs a SCCM command on a powershell host using Guest Operations and passes a machinename as a string, as a parameter to a powershell script located on the powershell host which adds the machine to an SCCM Collection. This works fine.

Now when adding this workflow to a larger workflow and mapping the already available "machinename" In Parameter to this workflow, the command runs, but for some reason the machine is not added to the Collection in SCCM. I know the script is running as I have some logging and it is outputting to a file, but this does not cover any errors. I have added some log outputs to the workflow and verified that the strings passed to the guest are the same in both instances. I did have an issue with Powershell complaining that the variable wasn't of type System.string but I got round that one by using the string() function in JavaScript. is ther still something funny about this type?

The code is below but very lightly modified from the Standard "Run Command in Guest" workflow:

var host = vm.sdkConnection;

var guestOperationsManager = host.guestOperationsManager;

var guestAuth = new VcNamePasswordAuthentication();

guestAuth.username = vmUsername;

guestAuth.password = vmPassword;

guestAuth.interactiveSession = interactiveSession;

var guestProgramSpec = new VcGuestProgramSpec();

guestProgramSpec.programPath = programPath;

guestProgramSpec.arguments = arguments + ' "' + String(machineName) + '"';

guestProgramSpec.workingDirectory = workingDirectory;

guestProgramSpec.envVariables = environment;

System.log("Issuing command on Powershell Host: " + programPath + " " + arguments + ' "' + machineName + '"');

var processManager = guestOperationsManager.processManager;

result = processManager.startProgramInGuest(vm , guestAuth , guestProgramSpec);

System.log("Result of Command Issuance = " + result);

3 Replies
igaydajiev
VMware Employee
VMware Employee

It would help if you provide sample workflow demonstrating the issue

Also try to output String(machineName).

0 Kudos
chicagovm
Enthusiast
Enthusiast

Does this code assume the SCCM agent is already installed or does it install and then add the machine to SCCM collection? I am curious as I am trying to run the install agent PS command from our PS host so when run from a Workflow, it would prompt for UserInteraction being that of $servername.

0 Kudos
JoJoGabor
Expert
Expert

I got to the bottom of this, nothing wrong with my code. I have the SCCM client anonymised in the VMware template and my code was running too quickly trying to add to the task sequence before the client had registered within SCCM. I now have some looping checks before proceeding,. it seems it can take around 5mins for the client to register