Skip to content

Instantly share code, notes, and snippets.

@msghens
Created September 19, 2017 18:48
Show Gist options
  • Select an option

  • Save msghens/d5b0fd0fd992487aad439807c02330d1 to your computer and use it in GitHub Desktop.

Select an option

Save msghens/d5b0fd0fd992487aad439807c02330d1 to your computer and use it in GitHub Desktop.
AD python user enable/disable snippets.
UC = int(entry['userAccountControl'][0])
UC = UC | (1 << 1)
mod_attrs = [ (ldap.MOD_REPLACE, 'userAccountControl', str(UC))]
try:
print dn,mod_attrs
l.modify_s(dn, mod_attrs)
except ldap.LDAPError, e:
print "Error disabling user %s" % e
#Reenable user
#print user_results[0][1]['userAccountControl'][0]
UC = int(user_results[0][1]['userAccountControl'][0])
if UC & (1<<1):
UC = UC & ~(1 << 1)
UCattrib = (ldap.MOD_REPLACE, 'userAccountControl', str(UC))
mod_attrs.append(UCattrib)
#print mod_attrs
ldapconn.modify_s( dn, mod_attrs )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment