Sub QueueApprovedDisables
 Dim objDB, sqlQuery
 num = 0
 Set objDB = CreateObject(“ADODB.Connection”)
 Set recordset = CreateObject(“ADODB.Recordset”)
 objDB.Open DB_CONNECT_STRING
 sqlQuery = “select uid from ” & DB_TABLE_DISABLES & ” where status = ‘Approved’ and archive_status = ‘pending'”
 recordset.Open sqlQuery, objDB
 objFS.CreateTextFile ExmergeFolder & server1List, TRUE
 objFS.CreateTextFile ExmergeFolder & server2List, TRUE
 Do While Not recordset.EOF
   QueueMailbox(recordset.Fields(“uid”))
   recordset.MoveNext
 LoopÂ
 objDB.Close
End Sub
Sub QueueMailbox(ByVal uid)
 Set WshShell = WScript.CreateObject(“WScript.Shell”)
 mailServer = “”
 Set objUser = Nothing
 ‘Connect to AD
 Set objConnection = CreateObject(“ADODB.Connection”)
 Set objCommand =  CreateObject(“ADODB.Command”)
 objConnection.Provider = “ADsDSOObject”
 objConnection.Open “Active Directory Provider”
 Set objCommand.ActiveConnection = objConnection
 ‘Get the user object
 On Error Resume Next
 Set objUser = GetObject(“LDAP://CN=” & uid & “,OU=People,” & RootDomain)Â
 If objUser Is Nothing Then
   WriteLog uid & ” not found”
 Else
   mailServer = objUser.Get(“msExchHomeServerName”)
   mailAddress = objUser.Get(“mail”)
   mailNickname = Left(mailAddress, Instr(mailAddress, “@”) -1)
   If InStr(mailServer,”server1″) > 0 Then
     Set objFile_electraList = objFS.OpenTextFile(ExmergeFolder & server1List,ForAppending,true)
     objFile_server1List.WriteLine DNprefix & mailNickname
     objFile_server1List.Close
     WriteLog “Mailbox queued for archiving ” & DNprefix & mailNickname
     ChangeArchiveStatus uid, “queued”
   ElseIf InStr(mailServer,”server2″) > 0 Then
     Set objFile_server2List = objFS.OpenTextFile(ExmergeFolder & server2List,ForAppending,true)
     objFile_server2List.WriteLine DNprefix & mailNickname
     objFile_server2List.Close
     WriteLog “Mailbox queued for archiving ” & DNprefix & mailNickname
     ChangeArchiveStatus uid, “queued”
   End If
 End If
 On Error Goto 0
 objConnection.Close
End Sub
Sub ChangeArchiveStatus(ByVal uid, ByVal newStatus)
 Dim objDB, sqlQuery
 Set objDB = CreateObject(“ADODB.Connection”)
 Set recordset = CreateObject(“ADODB.Recordset”)
 objDB.Open DB_CONNECT_STRING
 sqlQuery = “update ” & DB_TABLE_DISABLES & ” set archive_status = ‘” & newStatus & “‘ where uid = ‘” & uid & “‘”
 recordset.Open sqlQuery, objDB
 objDB.Close
End Sub