- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2014 12:35 PM
Details : I'm attempting to setup a Run Powershell workflow activity to run a command line utility on a remote server. The WF activity doesn't seem to be connecting to the remote server as desired and allow me to execute the command. It appears to be trying to run against my local midserver.
I can successfully run a "get-wmiobject" against the remote server. I'm also able to open a remote Powershell session from our midserver and execute the command successfully.
Here is the command I am trying to run: C:\Program Files (x86)\Good Technology\Good Mobile Control\jre\bin\ cmd /c 'GoodLinkAddUser.bat -Url=domain\<username>:<password>@https://localhost:19005 -GLS=<servername> -UserDisplayName="User Name" -PolicySet="DH Default Personal Device Good Mobile Messaging" -LogFile=GoodLinkAddUser.log'
Is there something special I need to add to the workflow activity in order to run the command on the remote server? I've tried Invoke-command and enter-pssession, but no success.
Thank you for any help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2014 08:20 AM
I finally worked out the Powershell command to run an external executable on a remote machine.
- Use the "Invoke-Command" commandlet
- Pass in the remote computer name ($computer)
- Pass in the credentials for the remote computer ($cred)
- Execute you script within -ScriptBlock { }
In the example below, I'm running a batch file on our Good Enterprise Server to add a user
Invoke-Command -ComputerName $computer -credential $cred -ScriptBlock {Set-Location -Path 'C:\Program Files (x86)\Good Technology\Good Mobile Control\jre\bin\'; $Out = cmd /c 2>&1 'GoodLinkAddUser.bat -Url=domain\username:password@https://localhost:19005 -GLS=servername -UserDisplayName="${workflow.scratchpad.uname}" -PolicySet="Policy name" -LogFile=GoodLinkAddUser.log' | Out-String; echo $Out}
Notes when running external executable within Powershell
- Powershell will interpret anything returned by the external executable/batch file as an error, which will cause the Run Powershell activity to always fail although the Scriptblock successfully added a user to Good.
- I worked around this by setting the output to a variable ($out) and then echoing the output at the end of the script.
- I could then do some further evaluation of the output in order to complete the workflow.
Sample from my Run Powershell Sensor Script:
workflow.scratchpad.results = output;
if(workflow.scratchpad.results.toString().toLowerCase().indexOf('successfully created user') > 0){
current.work_notes = 'The requester has been successfully setup for Good Messaging and notified of account setup.';
}
else if (workflow.scratchpad.results.toString().toLowerCase().indexOf('good messaging\nenabled') > 0) {
current.work_notes = 'The requester already Good Messaging enabled. Notifying Service Desk for further investigation';
}
else{
current.work_notes = 'The Good setup script encountered an error. Please investigate further. \n\nError Log: ' + output;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2014 06:46 AM
Subash
You are correct. We had PSremoting enabled on the remote machine and we were able to successfully run the command. The issue I was encountering was with how PS was handling return codes from the external command. That is where I had to suppress the output to a variable and then check it in the sensor script.
Rick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2015 09:49 AM
Can you do this the same activity without Orchestration?
Regards,
ND

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2015 09:05 AM
ND,
I believe you can run most probes even if you do not have Orchestration. This was true until Eureka release, I have not verified with Fuji or Geneva yet.
You can launch it using a background script or a run script action in a Workflow. You can add parameters as needed and define your own sensors. In the snippet below we defined a PowerShell probe and invoked it from a WF run script action passing the necessary dynamic parameters.
var probe = SncProbe.getById("1c9773d16f87210057369be44b3ee458"); // <-- pass the sys_id of the PowerShell probe here
probe.setTopic("Powershell");
probe.setName("Windows - Powershell");
probe.setSource("127.0.0.1");
probe.addParameter("powershell_fileName", fqhn);
probe.addParameter("powershell_keySize", ''+keySize);
probe.addParameter("powershell_myCrt", ''+myCRT);
workflow.scratchpad.eccsysid = probe.create("mid.server.abc_MID_SERVER");//pass the probeID to the WF scratchpad
Let me know if you have any further questions, thanks,
Subash Biswas