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?
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"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With