4

I'm using powershell 4 to invoke the Mirth Connect command line interface (mccommand.exe). I am explicitly avoiding use of the "-s" parameter of the Mirth CLI to pass a Mirth script file because I want to pass dynamic commands instead to the Mirth Shell.

When I invoke mccommand.exe from an interactive powershell console, I am able to connect to the Mirth Connect server and the Mirth Shell is opened where I can run one or more Mirth Shell commands to manage Mirth Channels.

Example:

. "C:\Program Files (x86)\Mirth Connect\mccommand.exe" -a "https://localhost:8443" -u admin_user -p admin_password
Connected to Mirth Connect server @ https://localhost:8443 (3.4.1.8057)
$

When I run the same command from within a powershell script via the Windows Powershell ISE, I get the same "Connected to Mirth Connect server @ https://localhost:8443 (3.4.1.8057)" message but the script waits and I never get the "$" command prompt that allows me to pass Mirth Shell commands to Mirth.

Any thoughts on how I can route commands to the Mirth Shell via a Powershell script?

Adam Flynn
  • 949
  • 2
  • 9
  • 21
  • Not sure if this helps, since I can't test it, but you may want to use the call operator (`&`) instead of the dot operator (which has a different purpose). – Ansgar Wiechers Jul 16 '16 at 10:00

2 Answers2

4

So you have to pass all the mirth shell commands as text file. This is what I use to import and deploy any channel.

Follow the below code:

Set-Location 'C:\Mirth Connect'
$ChannelOutput=.\mccommand.exe -a https://localhost:38443 -u username -p password -s "C:\commands.txt"

If($ChannelOutput -like '*successfully*')
{
"Channel created successfully and deplyed"
}
else
{
$_.Exception.Message
}

The Text file should have the set of commands like the below:

Commands.txt: 
 import "C:\TestServiceChannel1.xml" Force
channel deploy "Channel_name"
Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
1

An update, I have written a PowerShell wrapper for the Mirth REST API. Only really tested on Mirth 3.6 so far and written in PowerShell v5.1, the default that came with Windows 10. This allows you to write PowerShell scripts that can do anything the Mirth admin console can do.

https://github.com/naql/PS_Mirth

naql
  • 25
  • 5