Script to Check if User Exists in Active DIrectory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2019 09:51 AM
I've modified the LDAP Refresh UI Action button to be visible if a User's record has a User ID but the Source field is empty. When clicked, it passes the user ID, and scours the OU for the ID listed as sAMAccountName. This works via the button, however, I'd like to run a background or fix script to query ALL user records that match the criteria and run it for each of them.
Unfortunately, when I did this in a background script, only 1 or 2 of the 200+ records actually connect to LDAP each time it's run. It seemed like a timing issue, so I added a gs.sleep query thinking that would help, but it hasn't.
Has anyone accomplished this type of a query before?
var item = new GlideRecord('sys_user');
item.addEncodedQuery('sourceISEMPTY^user_nameISNOTEMPTY^active=true');
item.orderBy('user_name');
item.query();
while(item.next())
{
var user = item.user_name;
gs.info("Checking User ID: " + user);
var ldap = new GlideRecord('ldap_ou_config');
//var user = current.user_name.toString();
ldap.addQuery('name','XXXXXXXXX User Lookup');
ldap.query();
while(ldap.next())
{
ldap.filter = 'sAMAccountName='+user.toString();
gs.addInfoMessage("Filter is: " + ldap.filter);
ldap.update();
}
var rec = new GlideRecord('scheduled_import_set');
rec.addQuery('name','XXXXXXX User Import');
rec.query();
while (rec.next()){
gs.info("UPDATING SYS_ID: " + rec.sys_id);
SncTriggerSynchronizer.executeNow(rec);
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2019 12:53 PM
Is it possible that your issue is caused by attempting to update the same 'XXXXXXXXX User Lookup' record in the 'ldap_ou_config' table?