Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- domainname = raw_input("Domain Name: ")
- suffix = raw_input("Domain Suffix: ")
- alpha = ""
- num = ""
- alpha += "abcdefghijklmnopqrstuvwxyz"
- alpha += "abcdefghijklmnopqrstuvwxyz".upper()
- alpha += "1234567890"
- num += "1234567890"
- passwords = ""
- passwords2 = []
- onepassword = False
- print 'format: FirstName,LastName,Organisational Unit'
- usersfile = raw_input("CSV file for users: ")
- f=open(usersfile,'r')
- data=f.read().splitlines()
- f.close()
- seconddata="""
- $Rights = [System.Security.AccessControl.FileSystemRights]"Modify,ReadAndExecute,ListDirectory,Read,Write"
- $InheritanceFlag = @([System.Security.AccessControl.InheritanceFlags]::ContainerInherit,[System.Security.AccessControl.InheritanceFlags]::ObjectInherit)
- $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
- $objType =[System.Security.AccessControl.AccessControlType]::Allow
- """
- alldata="echo off\ncls\n"
- ous=[]
- d=raw_input("Site: ")
- for i in data:
- i=i.split(',')[2]
- if not i in ous:
- alldata+="DSADD OU \"OU="+i+",OU="+d+",DC="+domainname+",DC="+suffix+"\"\n"
- ous.append(i)
- print 'Added OU: '+i
- #if raw_input("Add OUs? (y/n)").upper() == 'Y':
- # print "Enter '#' to finish."
- # ouname = ''
- # while ouname != '#':
- # ouname = raw_input("OU Name: ")
- # if ouname != '#':
- # alldata+="DSADD OU OU="+ouname+",DC="+domainname+",DC="+suffix+"\n"
- print "Enter password for all users,"
- print "Leave blank for random passwords."
- passwords = raw_input("Password: ")
- if passwords == "":
- passwordexpire = 'no -mustchpwd yes '
- lenth = raw_input("Password Lentgh: ")
- for i in range(0,len(data)):
- while True:
- tmp=""
- for ii in range(0,int(lenth)):
- tmp += alpha[random.randint(0,len(alpha)-1)]
- #print tmp
- t2=False
- for b in num:
- if b in tmp:
- t2=True
- if t2:
- passwords2.append(tmp)
- break
- else:
- passwordexpire = 'yes'
- onepassword=True
- print "EG: \\\\192.168.1.1\\HOMEDIR"
- homedir = raw_input("Home Dir Path:")+'\\'+d
- count = 0
- passworddata=""
- for i in data:
- i2=i.split(',')
- firstname=i2[0]
- lastname=i2[1]
- group=i2[2]
- tmp='\n'
- if onepassword:
- passwd = passwords
- else:
- passwd = passwords2[count]
- count += 1
- passworddata += firstname+lastname[0]+':'+passwd+'\n'
- tmp += 'DSADD USER "CN=' + firstname + ' ' + lastname + ',OU=' + group + ',OU=' + d + ',DC='+domainname+',DC='+suffix+'" -disabled no -pwd '+passwd+\
- ' -samid ' +firstname + lastname[0] + ' -upn '+firstname + lastname[0] +'@'+domainname+'.'+suffix+' -fn '+ firstname +' -ln ' + lastname +\
- ' -display "'+firstname+' '+lastname+'" -pwdneverexpires '+passwordexpire+' -hmdir "'+homedir+'\\'+group+'\\'+firstname+'-' +\
- lastname+'" -hmdrv H:\n'
- alldata += tmp
- seconddata +='$NewFolder = New-Item -Path "'+homedir+'\\'+group+'" -Name '+firstname+'-'+lastname+' -ItemType "Directory"\n'
- seconddata +='$objUser = New-Object System.Security.Principal.NTAccount "'+domainname+'.'+suffix+'\\'+firstname+lastname[0]+'"\n'
- seconddata +='$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $Rights, $InheritanceFlag, $PropagationFlag, $objType)\n'
- seconddata +='$ACL = Get-Acl -Path $NewFolder\n $ACL.AddAccessRule($objACE)\nSet-ACL -Path $NewFolder.FullName -AclObject $ACL\n\n'
- f=open('files/users.bat','w')
- f.write(alldata)
- f.close()
- f=open('files/permissions.ps1','w')
- f.write(seconddata)
- f.close()
- f=open('files/userspasswords.txt','w')
- f.write(passworddata)
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement