Bulk Modify AD User Properties Python script

Source: Internet
Author: User

Bulk Modify AD User Properties Python script

The main is to use Python call dsquery query to the DN, and then use Python call dsmod to make the DN property modification.

Namelist.txt format as follows, the Department of the field can actually be changed to the corresponding ad attributes, such as the title of the ad in the position, want to modify the job number-position, the dsmod statement is changed to the following (specific dsmod user parameters dsmod user/? can see. )

"dsmod user" + DN + "-title" + dep

|---------------|

|SAMACCOUNT,DEP |

| work number, Department |

|---------------|

The code below requires administrator privileges to execute dsmod:

#coding =utf-8import osdef getdn (Gonghao):     z = os.popen ("dsquery  user -samid  + gonghao). Read ()     return z def cud (DN, DEP):     ' change users depatment '     try:         z = os.popen ("dsmod user "  + dn +  "  -dept  " + DEP". Read ()         return z     except:print  ' Can ' t find user  ' dicfile = open (' namelist.txt ', ' R ') dic1 = {}dic2 = {} #make  dic1,dic1 format from text filefor  line in dicfile:    a = line.strip (). Split (', ')      dic1[a[0]] =  a[1]dicfile.close () #print   ' Dic1 ', Dic1#make dic2, dic2  is {dn:depatement}foR k,v in dic1.iteritems ():     print k,v    dic2[ Getdn (k)] = vprint  ' * ' *10,dic2for i in dic2:#    print  ' i=%s '  %i, ' dic2[i]=%s '  %dic2[i]    if dn== ':p ass     Else:cud (I.strip (), Dic2[i])


This article from the "July" blog, reproduced please contact the author!

Bulk Modify AD User Properties Python script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.