JScript Active Directory object GUID

Author Johnny Josefsson on May 14, 2011 | Print | Bookmark
function userADobjectGUID(u_distinguishedName)
{
  var hexToStrGUID;
  var usr = GetObject("LDAP://" + u_distinguishedName);
  var GUIDStr = "";
  var usrGUID = usr.GUID;

  strGUID = usrGUID.substr(6, 2);
  strGUID = strGUID + usrGUID.substr(4, 2);
  strGUID = strGUID + usrGUID.substr(2, 2);
  strGUID = strGUID + usrGUID.substr(0, 2);
  strGUID = strGUID + usrGUID.substr(10, 2);
  strGUID = strGUID + usrGUID.substr(8, 2);
  strGUID = strGUID + usrGUID.substr(14, 2);
  strGUID = strGUID + usrGUID.substr(12, 2);
  strGUID = strGUID + usrGUID.substr(16, usrGUID.length);

  hexToStrGUID = "{" + strGUID.substr(0, 8)
                         + "-" + strGUID.substr(8, 4)
                         + "-" + strGUID.substr(12, 4)
                         + "-" + strGUID.substr(16, 4)
                         + "-" + strGUID.substr(20, 15) + "}";

  return hexToStrGUID;
} 

Was this article helpful?

Yes No

Category: Scripting, JScript

Last updated on May 15, 2011 with 1165 views