Erdinc Pinar
Tera Contributor

I would like to share some information about creating an activity to check more than one MSMQ and getting more than one result in one transaction. By using this activity, save the number of licensed transactions.

Details are below;

Create New Activity

-Open Workflow Editor and add new activity under Custom Tab.
-Select PowerShell.

find_real_file.png

General Tab

-Set a name for the activity.
-Click Continue.

find_real_file.png

Inputs Tab

-Add 2 inputs which are hostname and msmqcheck_script.

find_real_file.png

Execution Command Tab

-Set hostname to the target host.
-Set msmqcheck_script to command.

find_real_file.png

 

Outputs Tab

-Create two outputs which are output and errorMessages.
-Determine the parsing rule for outputs.

find_real_file.png

-Click Go to Post-Processing.

Post Processing Tab

In this tab, the output should be parsed by using javascript.

(Note: If not click Go to Post-Processing under outputs tab, Post Processing tab will not be visible.)

find_real_file.png

Code1

var array = [];
// Start to get output and split breakline.
var desc = executionResult.output;
var sdesc = desc.split('\n');
for(var i =0;i<sdesc.length;i++){
//Get row which has \\ because msmq’s format should hostname\\msmqname
if(sdesc[i].indexOf('\\')>-1){
var ldesc = sdesc[i];
//Split row by row.Because result will be like hostname\\msmqname 10
var lastdesc = ldesc.split(' ');
if(lastdesc[1]!=0){
array.push(ldesc+'\n');
}
}
}
//If msmq’ value is empty, output will be 0.
if(array.toString()!=''){
activityOutput.output = array.toString();}
else if(array.toString()==''){
activityOutput.output = '0';
}

Conditions Tab

No Message -> activityOutput.errorMessages == null && activityOutput.output == 0
Has Message -> activityOutput.errorMessages == null && activityOutput.output != 0
Error -> activityOutput.errorMessages == null && activityOutput.output != 0

find_real_file.png

After creating MSMQ Check activity, create a workflow to orchestrate it.

MSMQ Check Workflow

-Create workflow and add MSMQ Check activities and Run Script.

find_real_file.png

MSMQ_Check Activity Input

- Set workflow.scratchpad.msmqcheck_script to Msmqcheck script field.
- Set host name that this activity runs.

find_real_file.png

MSMQ Check Workflow Input

-Create workflow input that set MSMQs name.
-This column name used in Run Script.

find_real_file.png

Run Script (MSMQ List to Check)
This Run Script get MSMQ list and prepare PowerShell script that can change due to inputs dynamically.

find_real_file.png

Code2

// u_msmqs_to_be_checked – inputs column name of field
//This code get all msmqs. Firstly, get host name and msmqs name. Then, system is created Powershell script.

var msmqs_list = workflow.inputs.u_msmq_list;
var arrayUtil = new ArrayUtil();
var array = [];
var msmqdata = [];
var list = msmqs_list.split(';');
for(var i =0;i<list.length;i++){
if(list[i].indexOf('\\')>-1){
var msmqrec = list[i];
var host = msmqrec.substr(0, msmqrec.indexOf('\\'));
msmqdata.push([host,msmqrec]);
if(arrayUtil.contains(array, host))
{
}else{
array.push(host);
}
}
}
var script = '';
for(t=0;t<array.length;t++){

if(t>0){
script= script +"\";$queues | ft -property Name,MessagesInQueue;";
}
if(script == '') script = "$queues = Get-WmiObject Win32_PerfRawData_MSMQ_MSMQQueue -computer "+array[t]+" -Filter ";
else script = script + "$queues = Get-WmiObject Win32_PerfRawData_MSMQ_MSMQQueue -computer "+array[t]+" -Filter ";
var z = 0;
for(k=0;k<msmqdata.length;k++)
{
if(arrayUtil.contains(msmqdata[k],array[t])){
z++;
if(z==1) {
//gs.log('array[t]='+array[t]);
script = script + "\"name = \'"+msmqdata[k][1]+"\'";}
else if(z>1){
//gs.log('array[t]1='+array[t]);
script = script + " or name = \'"+msmqdata[k][1]+"\'";}
//gs.log('ep='+msmqdata[k][1]);
}
}
}
script = script + "\";$queues | ft -property Name,MessagesInQueue";
workflow.info("script="+script);
workflow.scratchpad.msmqcheck_script = script;

Example of the PowerShell script that created by javascript is below.

Get-WmiObject Win32_PerfRawData_MSMQ_MSMQQueue -computer hostname1 -Filter "name = 'hostname1\\msmq1' or name = 'hostname1\\msmq2' or name = 'hostname1\\msmq3' '";$queues | ft -property Name,MessagesInQueue;$queues = Get-WmiObject Win32_PerfRawData_MSMQ_MSMQQueue -computer hostname2 -Filter "name = 'hostname2\\msmq4'";$queues | ft -property Name,MessagesInQueue

 

 

Version history
Last update:
‎03-06-2019 03:08 PM
Updated by: