I found a solution. The problem was extra information was being captured by orchestrators' command output. It was capturing the Result of Query, But Included a Line break/CR (Even when Piping Straight into DSRM).
Solution was to run 2 Seperate Commands: Run dsquery and then perform a regex to capture only the DN. Then run DSRM with that DN. Works great, and means I only need to supply the computer name and credentials for deletion.
Thanks heaps to qc4vmware for the assistance.
Here is the updated code:
var returnVal = false;
//Query AD For DN of Computer
var commandQuery = "dsquery.exe computer -name " + computer + " -u " + username + " -p " + password
//execute Query command
var cmd = new Command(commandQuery);
cmd.execute(true);
var output = cmd.output
//need to remove any extra garbage from the output
var DNs = output.match("\".*\"")
//Log Results for DSQuery
System.log("QUERY RESULTS");
System.log("Command: " + cmd);
System.log("Command result: " + cmd.result);
System.log("Command output: " + cmd.output);
System.log("DN Match is " + DNs[0])
var commandDelete = "dsrm " + DNs[0] + " -noprompt " + " -u " + username + " -p " + password
System.log("Delete Command : " + commandDelete)
//execute Delete command
var cmd = new Command(commandDelete);
cmd.execute(true);
//Log Results for DSRM
System.log("DELETION RESULTS")
System.log(cmd)
System.log("Command result: " + cmd.result);
System.log("Command output: " + cmd.output);
if (cmd.result == 0 && cmd.output.indexOf("dsrm succeeded") >= 0) {
System.log("AD computer object deletion successful with DSRM.");
returnVal = true;
}
else {
System.log("Failed to remove computer object from AD!");
}
return returnVal;