commonfields:
  id: RemoteExec
  version: 1
name: RemoteExec
script: |-
  //Execute a command on a remote machine
  var output = [];
  var entries = executeCommand("ssh", {system: args.system, cmd: args.cmd});
  var ret = entries[0];
  if (ret === null) {
      output.push({ContentsFormat: formats.text, Type: entryTypes.error, Contents: "Failed to execute remote command."});
  } else {
      result = ret.Contents;
      if (!result.success) {
          output.push({ContentsFormat: formats.text, Type: entryTypes.error, Contents: result.error});
      } else {
          output.push({ContentsFormat: formats.text, Type: entryTypes.note, Contents: result.output});
      }
  }
  return output;
type: javascript
tags:
- endpoint
comment: Execute a command on a remote machine (without installing a D2 agent)
system: true
args:
- name: system
  required: true
  description: Name of system on which to run the command
- name: cmd
  required: true
  description: Command to run
scripttarget: 0
dependson:
  must:
  - ssh
timeout: 0s

commonfields:
  id: RemoteExec
  version: 1
name: RemoteExec
script: |-
  //Execute a command on a remote machine
  var output = [];
  var localSystem = false;
  for (var s = 0; s < investigation.systems.length; s++) {
      if (investigation.systems[s].name === args.system) {
          localSystem = true;
          break;
      }
  }
  var params = localSystem ? {system: args.system, cmd: args.cmd} : {using: args.system, cmd: args.cmd};
  var entries = executeCommand("ssh", params);
  var ret = entries[0];
  if (ret === null) {
      output.push({ContentsFormat: formats.text, Type: entryTypes.error, Contents: "Failed to execute remote command."});
  } else {
      result = ret.Contents;
      if (!result.success) {
          output.push({ContentsFormat: formats.text, Type: entryTypes.error, Contents: result.error});
      } else {
          output.push({ContentsFormat: formats.text, Type: entryTypes.note, Contents: result.output});
      }
  }
  return output;
type: javascript
tags:
- endpoint
comment: Execute a command on a remote machine (without installing a D2 agent)
system: true
args:
- name: system
  required: true
  description: Name of system on which to run the command
- name: cmd
  required: true
  description: Command to run
scripttarget: 0
dependson:
  must:
  - ssh
timeout: 0s

Make sure that RemoteExec works with RemoteAccess integrations as well as local systems
Make sure that RemoteExec works with RemoteAccess integrations as well as local systems
