03-08-2016 11:29 AM
Hello,
I am in charge of MEGA support and I would like to extract automatically in csv file all users from all environments with a VBScript.
We have developed a VBscript for that. Everything is OK if we extract the user from one Environment.
But when we try to extract the users from all environments, only the users of first environment in the loop are extracted and that only for HOPEX version; when I use the script on MEGA 2009 everything works correctly...
Here under, you could find the function that I use to extract the user. It seems that the script does not enter the loop:
"For Each oTransaction in oEnvironment.Transactions" from the second environment.
Public Sub AllUsersExtraction(outputFile, sAdministrator, sAdminPwd)
On Error Resume Next
Dim oMegaApp, oEnvironment, oTransaction, oRoot, oUser, oLogin
Dim sEnvPath, sDatabase
Dim cUsers, cLogins
Dim bGenerationSucceeded
WriteLineInLogFile "Preparing generation of all user extract", "4-info"
bGenerationSucceeded = False
Set oMegaApp = Nothing
Set oMegaApp = CreateObject("Mega.Application")
If CheckError("MEGA application instance creation") Then
For Each oEnvironment in oMegaApp.Environments
WriteLineInLogFile "Start of user extraction of " & oEnvironment.path, "4-info"
outputFile.writeline oEnvironment.path
If oEnvironment Is Nothing Then
WriteLineInLogFile "Cannot find environment specified", "1-fatal"
Else
oEnvironment.CurrentAdministrator = sAdministrator
oEnvironment.CurrentPassword = sAdminPwd
For Each oTransaction in oEnvironment.Transactions
If CheckError("MEGA transaction creation") Then
Set oRoot = oTransaction.Database.Open
If CheckError("MEGA session open") Then
Set cUsers = oRoot.GetCollection("Person (System)")
for each oUser in cUsers 'boucle sur les utilisateurs
set cLogins = oUser.getCollection("~A20000008880[Login]") 'chercher les informations de la classe login correspondant à l'utilisateur
set oLogin = clogins.Item(1) 'prendre le premier login trouvé (de toute façon normalement il n'y en a qu'un)
outputFile.write oLogin.getProp("Windows_login") & ";;" & oUser.GetProp("E-mail") & ";;;;" & oEnvironment.path 'écrire les infos du user
outputFile.writeline ""
next
Set cUsers = Nothing
bGenerationSucceeded = CheckError("MEGA users extraction")
End If
Set oRoot = Nothing
End If
Set oTransaction = Nothing
Next
WriteLineInLogFile "End of user extraction of " & oEnvironment.path, "4-info"
End If
Set oEnvironment = Nothing
Next
End If
Set oMegaApp = Nothing
If bGenerationSucceeded Then
WriteLineInLogFile "End of copy of extraction", "4-info"
End If
End Sub
Could you please help me on this problem?
In addition, I have another question:
Is it possible to extract the users using a MEGA request: Select [Person (System] Where [Name] not like "something#"?
When we use the script directly in MEGA we use the function:
Set cUsers = GetCollection(Select [Person (System] Where [Name] not like "something#"
But with a Vbscipt we use, the function
Set cUsers = oRoot.GetCollection("Person (System)")So to filter the users, we must add some conditions in the script after the extraction.
Thank you in advance,
Best regards,
04-08-2016 07:10 AM
Hello,
Instead of goind through original transactions create a new one, and disregard at the end before moving on to another environment.
I would suggest just use "oRoot.getSelection("Select [Person (System)] where Name like 'something#' ")"