Import user accounts from domain A to domain B

You can share your Lua Scripts with everybody here.

Import user accounts from domain A to domain B

Postby FTP » Wed Jun 09, 2010 5:03 am

-- Description: Import user accounts from domain1 to domain2, support XML, ODBC, Mysql
-- Author: Luke
-- Date: 2010-06-08

Code: Select all
local pages = c_GetUserPageCount("domain1")
if pages == 0 then pages = 1 end

for i=1,pages do
   local userlist = Split(c_GetUserListPage("domain1",i), "\n")

   for _,username in pairs(userlist) do
      local myuser = c_GetUser("domain1",username)

      if myuser ~= nil then
         myuser.oldpassword = myuser.password

         for k,v in pairs(myuser) do
           if type(v) == "boolean" then
             if v == true then
               myuser[k] = 1
             else
               myuser[k] = 0
             end
           end
         end

         AddUser("domain2",myuser)
      end
   end
end
FTP
Site Admin
 
posts 1202
 
joined Tue Sep 29, 2009 6:09 am

Re: Import user accounts from domain A to domain B

Postby FTP » Fri Mar 08, 2013 9:02 am

BTW, if you want to import all the groups, just use the following script:


Code: Select all
local pages = c_GetGroupPageCount("domain1")
if pages == 0 then pages = 1 end

for i=1,pages do
   local grouplist = Split(c_GetGroupListPage("domain1",i), "\n")

   for _,groupname in pairs(grouplist) do
      local mygroup = c_GetGroup("domain1",groupname)

      if mygroup ~= nil then

         for k,v in pairs(mygroup) do
           if type(v) == "boolean" then
             if v == true then
               mygroup[k] = 1
             else
               mygroup[k] = 0
             end
           end
         end

         AddGroup("domain2",mygroup)
      end
   end
end
FTP
Site Admin
 
posts 1202
 
joined Tue Sep 29, 2009 6:09 am


Return to Lua scripts

Who is online

Users browsing this forum: No registered users and 1 guest