Question QUESTION: Hello,
I have this script:
This code prints the last logon timestamp for a user.
' ------ SCRIPT CONFIGURATION ------
strUserDN = "<UserDN>" ' e.g. cn=rallen,ou=Sales,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------
This script works perfectly for one user. I am asking for your help to modify this script to work for a list of users which i have in a txt(every user is on a new line in the txt) and to make an export of the result in a tab delimited file.
Can you help me?
Many thanks in advance.
ANSWER: Raducu,
create a text file and save as "userlist.txt" at "c:\" and past your all userdn. Make sure there will be no header row in text file.
Try below code and let me know if any issue there.
Subbu.
dim userDN
' Get a free file number
nFileNum = FreeFile
' Open a text file for input
Open "C:\userlist.txt" For Input As nFileNum
' Read the contents of the file
Do While Not EOF(nFileNum)
Line Input #nFileNum, userDN
'MsgBox snextline
------ SCRIPT CONFIGURATION ------
strUserDN = userDN ' e.g. cn=rallen,ou=Sales,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------
QUESTION: Hello, this is the error that i get :
(5, 24) Microsoft VBScript compilation error: Expected end of
statement
Can you help please?
Many thanks!
ANSWER: Raducu,
May I know where you are executing this code?
I mean in Access VBA or Excel VBA or Visual studio?
If possible can you take a screen print and attach the same?
Subbu.
---------- FOLLOW-UP ----------
QUESTION: Hi Subbu,
I run the script in comand promt on a Domain Controller.
I managed to modify the script to do what I wanted but I have another problem now. Please see the code below:
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Const FOR_APPENDING = 8
Const FOR_READING = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\userlist1.txt", FOR_READING)
Do Until objFile.AtEndOfStream
strNextLine = objFile.Readline
arrServiceList = Split(strNextLine , " , ")
For i = 0 to Ubound(arrServiceList)
'------ SCRIPT CONFIGURATION ------
strUserDN = StrNextLine ' e.g. cn=rallen,ou=Sales,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------
Loop
The script works fine now but I want soem help to modify the following:
1) On Error the script returns the same value as the precedent value, something like this:
User1 20
User2 30
User3 30 ( here is an error )
User4 50 and so on. I want to write " Not Found" in case of error and continue the proccessing.
2) I don`t know how to export the output to a .txt file.
Can you help, especially with point 2)
Many thanks in advance.
Answer Raducu,
Regarding point 2:
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO1.OpenTextFile("C:\userlist2.txt", FOR_WRITING)
'To write text into file
'Make sure these two lines with in the loop
objFile2.WriteLine "User: " & arrServiceList(i)
objFile2.WriteLine "Approx last logon timestamp: " & intLogonTime + #1/1/1601#
Point 1:
I need more information like:
where exactly you will error?