def adduser(name, username):
 ret = {'name': name, 'result': True, 'changes': {'Users Added': []}, 'comment': ''}
 pythoncom.CoInitialize()
 nt = win32com.client.Dispatch('AdsNameSpaces')
 groupObj = nt.GetObject('', (('WinNT://./' + name) + ',group'))
 existingMembers = []
 for member in groupObj.members():
  existingMembers.append(member.ADSPath.replace('WinNT://', '').replace('/', '\\').encode('ascii', 'backslashreplace').lower())
 try:
  if (__fixlocaluser(username.lower()) not in existingMembers):
   if (not __opts__['test']):
    groupObj.Add(('WinNT://' + username.replace('\\', '/')))
   ret['changes']['Users Added'].append(username)
  else:
   ret['comment'] = 'User {0} is already a member of {1}'.format(username, name)
   ret['result'] = None
 except pywintypes.com_error as com_err:
  if (len(com_err.excepinfo) >= 2):
   friendly_error = com_err.excepinfo[2].rstrip('\r\n')
  ret['comment'] = 'Failed to add {0} to group {1}.  {2}'.format(username, name, friendly_error)
  ret['result'] = False
  return ret
 return ret

def adduser ( name , username ) : ret = { 'name' : name , 'result' : True , 'changes' : { 'Users Added' : [ ] } , 'comment' : '' } pythoncom . CoInitialize ( ) nt = win32com . client . Dispatch ( 'AdsNameSpaces' ) groupObj = nt . GetObject ( '' , ( ( 'WinNT://./' + name ) + ',group' ) ) existingMembers = [ ] for member in groupObj . members ( ) : existingMembers . append ( member . ADSPath . replace ( 'WinNT://' , '' ) . replace ( '/' , '\\' ) . encode ( 'ascii' , 'backslashreplace' ) . lower ( ) ) try : if ( __fixlocaluser ( username . lower ( ) ) not in existingMembers ) : if ( not __opts__ [ 'test' ] ) : groupObj . Add ( ( 'WinNT://' + username . replace ( '\\' , '/' ) ) ) ret [ 'changes' ] [ 'Users Added' ] . append ( username ) else : ret [ 'comment' ] = 'User {0} is already a member of {1}' . format ( username , name ) ret [ 'result' ] = None except pywintypes . com_error as com_err : if ( len ( com_err . excepinfo ) >= 2 ) : friendly_error = com_err . excepinfo [ 2 ] . rstrip ( '\r\n' ) ret [ 'comment' ] = 'Failed to add {0} to group {1}.  {2}' . format ( username , name , friendly_error ) ret [ 'result' ] = False return ret return ret
add a user in the group .