Created
September 19, 2017 18:48
-
-
Save msghens/d5b0fd0fd992487aad439807c02330d1 to your computer and use it in GitHub Desktop.
AD python user enable/disable snippets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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