code: def copy_user(target, user, password):
      # See if the user has firstName and lastName properties
      try:
          firstname = user.firstName
          lastname = user.lastName
      except:
          # if not, split the fullName
          fullName = user.fullName
          firstname = fullName.split()[0]
          try:
              lastname = fullName.split()[1]
          except:
              lastname = " "
  
      try:
          testuser = target.users.get(user.username)
          if not testuser is None:
              print(
                  "\tUsername {} already exists in Target Portal; skipping user creation.\n".format(
                      user.username
                  )
              )
              return testuser
  
          target_user = target.users.create(
              user.username,
              password,
              firstname,
              lastname,
              user.email,
              user.description,
              user.role,
              user.provider,
              user.idpUsername,
          )
  
          # update user properties from existing user
          target_user.update(
              user.access,
              user.preferredView,
              user.description,
              user.tags,
              user.get_thumbnail_link(),
              culture=user.culture,
              region=user.region,
          )
  
          # update user role; assumes no custom roles
          if "role" in user and not user.role == "org_user":
              target_user.update_role(user.role)
  
          return target_user
  
      except:
          print("Unable to create user " + user.username)
          return None
  
imports: from __future__ import print_function
  import sys
  import six
  from arcgis.gis import *
label_desc: Use image node_id 1 for calling a global function with example usage: copy_user(target, user, password) and returns: target_user, testuser, None