#To define a particular parameter, replace the 'parameterName' inside itsm.getParameter('parameterName') with that parameter's name
domain_name="test"  ## Please enter the domain name. Ensure the domain_name exists already.

import os
import subprocess
from subprocess import PIPE, Popen

gt=[]

try:
    wdir=os.environ['PROGRAMDATA']+'\\temp'a
    if not os.path.exists(wdir):
            os.mkdir(wdir)
except:
    wdir=os.environ['SYSTEMDRIVE']

fp=wdir+'\\users.txt'
cmd="wmic useraccount get name"
obj=subprocess.Popen(cmd, shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
out, err = obj.communicate()

with open(fp, 'w+') as dr:
    dr.write(out)

with open(fp, 'r+') as dr:
    for i in dr: None if 'Name' in i or 'DefaultAccount' in i or 'Guest' in i or 'Administrator' in i else gt.append(i.strip())

for i in filter(None, gt):
    obj = subprocess.Popen('net group "%s" %s /ADD /DOMAIN'%(domain_name, i), shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
    out, err = obj.communicate()
    print "The user : "+i+" has been successfully added to domain "+domain_name if out else err

try:
    os.remove(fp)
except:
    pass

print "Restarting the Machine to apply changes"
os.popen("shutdown.exe -r")
