Import user accounts from domain A to domain B

You can share your Lua Scripts with everybody here.
Post Reply
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Import user accounts from domain A to domain B

Post by FTP »

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

Code: Select all

local oldDomain = "domainA"
local newDomain = "domainB"
local pages = c_GetUserPageCount(oldDomain)
if pages == 0 then pages = 1 end

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

   for _,username in pairs(userlist) do

      local dbuserIndex = string.find(username, "|")
      if dbuserIndex then
         username = string.sub(username, 1, dbuserIndex-1)
      end

      local myuser = c_GetUser(oldDomain, 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(newDomain, myuser)
      end
   end
end
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Import user accounts from domain A to domain B

Post by FTP »

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

Code: Select all

local oldDomain = "domainA"
local newDomain = "domainB"
local pages = c_GetGroupPageCount(oldDomain)
if pages == 0 then pages = 1 end

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

   for _,groupname in pairs(grouplist) do
      local mygroup = c_GetGroup(oldDomain, 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(newDomain, mygroup)
      end
   end
end
niqbert
Posts: 18
Joined: Mon Jul 11, 2011 1:06 pm

Re: Import user accounts from domain A to domain B

Post by niqbert »

Cheers, this worked for me!
Post Reply