Storing PowerShell results in datastore

From SMTX Wiki
Jump to navigation Jump to search

This example takes the output of a powershell script and stores it in a datastore. The script returns 3 columns per line (; seperated) and an additional lookup is done in a JSON structure to find a matching key with a given code.

var textArea='Name1;email1;BGN\nName2;email2;BGN\nName3;email3;BG-Bau';
var lines = textArea.split('\n');
var i=0;
var lineFields = null;
var mandantList = {'BG-Bau': '37', 'BGN' : '18'};

CommonInterface.deleteParameterEntries('AD Emailgroups', {'DeleteDummy':1});

for(i = 0;i < lines.length;i++){
lineFields = lines[i].split(';');
CommonInterface.addParameterEntry('AD Emailgroups', {'Name': lineFields[0], 'Email': lineFields[1], 'Mandant': lineFields[2], 'MandantId' : mandantList[lineFields[2]], 'DeleteDummy': 1});
}
return(i+' Datensätze hinzugefügt in datastore AD Emailgroups')