Skip to content

Instantly share code, notes, and snippets.

@camrobert
Created December 2, 2022 12:45
Show Gist options
  • Save camrobert/bef7ab83a6245c7db40dd30c3f25f755 to your computer and use it in GitHub Desktop.
Save camrobert/bef7ab83a6245c7db40dd30c3f25f755 to your computer and use it in GitHub Desktop.
SSJS and WSProxy code to return all valid users in a Marketing Cloud instance
<script runat="server">
/*Code provided as is without warranty - make sure you understand what this code does before using it - use at your own risk*/
Platform.Load("Core","1");
try {
var prox = new Script.Util.WSProxy();
//================== https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/accountuser.html
var cols = ["Name","CustomerKey","NotificationEmailAddress", "UserID", "ActiveFlag", "Email", "IsAPIUser", "AccountUserID", "LastSuccessfulLogin", "CreatedDate", "Roles"];
//================= https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_WSProxy_basic_retrieve.html
var filter = {
LeftOperand: {Property: "Email",SimpleOperator: "like",Value: "@"},
LogicalOperator: "AND",
RightOperand: {Property: "ActiveFlag",SimpleOperator: "equals",Value: "true"}
};
var res = prox.retrieve("AccountUser", cols, filter);
Write(Stringify(res.Results)+"<br><br><br>");
Write("<table border=1><tr><th>Name</th><th>Email</th><th>CreatedDate</th><th>LastSuccessfulLogin</th><th>Roles</th></tr>");
for (i = 0; i < res.Results.length; i++) {
Write("<tr><td>" + res.Results[i].Name + "</td><td>" + res.Results[i].Email + "</td><td>" + res.Results[i].CreatedDate + "</td><td>" + res.Results[i].LastSuccessfulLogin + "</td><td>");
for (r = 0; r < res.Results[i].Roles.length; r++) {
Write(res.Results[i].Roles[r].Name + "<br>");
}
Write("</td></tr>");
}
Write("</table>");
}
catch(error) {
Write('Message: ' + error);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment