IT_Resource
asked on
the last logon timestamp for a user
' This VBScript code prints the last logon timestamp for a user.
' -------------------------- ---------- ---------- ---------- -------
' From the book "Active Directory Cookbook" by Robbie Allen
' ISBN: 0-596-00466-4
' -------------------------- ---------- ---------- ---------- -------
' ------ SCRIPT CONFIGURATION ------
strUserDN="cn=username, ou=usrou, dc=name01.pa.domain, dc=org"
' ------ END CONFIGURATION ---------
set objUser = GetObject("LDAP://" & strUserDN)
set objLogon = objUser.Get("lastLogonTime stamp")
intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
intLogonTime = intLogonTime / (60 * 10000000)
intLogonTime = intLogonTime / 1440
WScript.Echo "Approx last logon timestamp: " & intLogonTime + #1/1/1601#
I tried using the above VB script I found on the internet and tried to use it to get the last time a given user logged into the domain, this way I can find out if I can change the password on the user without risking it might be used somewhere.
My Domain is pretty big we have a main domain with several child domains to it
When I run the script this is what I get
Line:13
Char:1
Error: A referral was returned from the server
Code: 8007202B
Source: (null)
Thanks
error.jpg
' --------------------------
' From the book "Active Directory Cookbook" by Robbie Allen
' ISBN: 0-596-00466-4
' --------------------------
' ------ SCRIPT CONFIGURATION ------
strUserDN="cn=username, ou=usrou, dc=name01.pa.domain, dc=org"
' ------ END CONFIGURATION ---------
set objUser = GetObject("LDAP://" & strUserDN)
set objLogon = objUser.Get("lastLogonTime
intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
intLogonTime = intLogonTime / (60 * 10000000)
intLogonTime = intLogonTime / 1440
WScript.Echo "Approx last logon timestamp: " & intLogonTime + #1/1/1601#
I tried using the above VB script I found on the internet and tried to use it to get the last time a given user logged into the domain, this way I can find out if I can change the password on the user without risking it might be used somewhere.
My Domain is pretty big we have a main domain with several child domains to it
When I run the script this is what I get
Line:13
Char:1
Error: A referral was returned from the server
Code: 8007202B
Source: (null)
Thanks
error.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
From anywhere in the domain, as long as the user running it has permissions to read those attributes from AD.
Please paste the exact line that's giving you an error.
Please paste the exact line that's giving you an error.
D'oh! Yeah, I missed that..
You have to have the correct DN in order for this to work.
LOL
Good catch rejoinder
You have to have the correct DN in order for this to work.
LOL
Good catch rejoinder
ASKER
ok let's try this a little different
here is what I get on the Object tab
pa.domain.org/ABC/ABC Conversion
if I pulg that in shoudn't it look like this:
strUserDN="cn=ABC Conversion,ou=ABC,dc=pa.do main,dc=or g"
set objUser = GetObject("LDAP://" & strUserDN)
wscript.echo objUser.lastlogin
well if that's right it's still giving me the same error
here is what I get on the Object tab
pa.domain.org/ABC/ABC Conversion
if I pulg that in shoudn't it look like this:
strUserDN="cn=ABC Conversion,ou=ABC,dc=pa.do
set objUser = GetObject("LDAP://" & strUserDN)
wscript.echo objUser.lastlogin
well if that's right it's still giving me the same error
Make it look like this;
strUserDN="cn=ABC Conversion,ou=ABC,dc=pa,dc =domain,dc =org"
strUserDN="cn=ABC Conversion,ou=ABC,dc=pa,dc
Nope. Use this
strUserDN = "CN=ABC Conversion,OU=ABC,DC=pa,DC=domain,DC=org"
set objUser = GetObject("LDAP://" & strUserDN)
wscript.echo objUser.lastlogin
ASKER
Ok, what is line 3? Are there only 3 lines in the vbs file you're using? Please post line 3.
Most likely there's a fatfinger in the DN..
Most likely there's a fatfinger in the DN..
ASKER
set objUser = GetObject("LDAP://" & strUserDN)
If that line is the 3rd line then we have to go back to the distinguished name you are entering above.
Basically the script cannot find the user name you are entering. Perhaps there is a longer OU path tha is missing? If so, please come clean and lets see the users full path so we can help sort this out.
Basically the script cannot find the user name you are entering. Perhaps there is a longer OU path tha is missing? If so, please come clean and lets see the users full path so we can help sort this out.
ASKER
let me show you
pic.jpg
pic.jpg
Great - so I take it your script looks exactly like this...
If the script still does not work, then the OU PGM may be a container rather than an OU in which case you would need to use this as line 1;
strUserDN = "CN=PGM Conversion,CN=PGM,DC=na,DC =bpww,DC=o rg"
If the script still does not work, then the OU PGM may be a container rather than an OU in which case you would need to use this as line 1;
strUserDN = "CN=PGM Conversion,CN=PGM,DC=na,DC
strUserDN = "CN=PGM Conversion,OU=PGM,DC=na,DC=bpww,DC=org"
set objUser = GetObject("LDAP://" & strUserDN)
wscript.echo objUser.lastlogin
strUserDN = "CN=PGM Conversion,OU=PGM,DC=na,DC =bpww,DC=o rg"
Use that.
Use that.
ASKER
That means the account has never logged on... ??
ASKER
Rock on.
you guys are good at this.
how would you say it's fair to split some points here?
you guys are good at this.
how would you say it's fair to split some points here?
Hey this is all exx1976's script, I'd be happy with anything :-)
ASKER
Keep it up guys
Good Work
Good Work
ASKER
question
where would it be the safe to run this script from? on the DC or WS?