Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


VB script to list all expired accounts in an ou

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,32071
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VB script to list all expired accounts in an ou
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 VB script to list all expired accounts in an ou - 3/8/2006 8:23:36 PM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
Dear all,

Ii have got this script to check all expired accounts


      


but would like to create a script to list all accounts in an ou that accounts are due to expire in about 3 days and list in a text file.  Basically this is for our laptop users who keep forgetting to reset their passwords and then cant remotley login.  Has anyone got a script or could anyone be kind enough to point me in the right direction?

Many thanks

Aaron
 
 
Post #: 1
 
 RE: VB script to list all expired accounts in an ou - 3/9/2006 5:25:04 AM   
  ziminski

 

Posts: 79
Score: 2
Joined: 1/8/2006
Status: offline
Try using the following as a logon script. This would echo their account expiration date every time they log on.

On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
If IsNull(objUser.AccountExpirationDate) or objUser.AccountExpirationDate = "1/1/1970" Then
   Wscript.Echo "Your account has no expiration date."
Else
   Wscript.Echo You account expires on " & objUser.AccountExpirationDate & "."
End If

(in reply to AzzerShaw)
 
 
Post #: 2
 
 RE: VB script to list all expired accounts in an ou - 3/9/2006 8:30:56 PM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
Thanks for the reply.

We already prewarn the users at logon when there passwords will change.  However, the laptop users log on with cached profiles and dial-in.  So we really do need to run the script ourselves so we can send an email stating the account is due to expire and what to do if this happens.  (trying to be as pro-active as possible)

(in reply to ziminski)
 
 
Post #: 3
 
 RE: VB script to list all expired accounts in an ou - 3/9/2006 9:11:25 PM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
I just found this script


      

But i get an error in "line 43, char 44, error = Expected end of statement, code = 800A0401"

Has anyone got any ideas?

< Message edited by AzzerShaw -- 3/9/2006 9:17:00 PM >

(in reply to AzzerShaw)
 
 
Post #: 4
 
 RE: VB script to list all expired accounts in an ou - 3/9/2006 10:09:37 PM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
With blank lines included I only see 41 lines of code.  Remove "On Error Resume Next" from the top of the script, rerun and post what error you get, if different.


Cybex

_____________________________

Common sense is not so common.

(in reply to AzzerShaw)
 
 
Post #: 5
 
 RE: VB script to list all expired accounts in an ou - 3/9/2006 10:16:12 PM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
I then get error on Line 40, Char 44, error = expected end of statement, code = 800A0401

(in reply to Cybex)
 
 
Post #: 6
 
 RE: VB script to list all expired accounts in an ou - 3/10/2006 12:35:29 AM   
  Country73


Posts: 733
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
You may want to actually include the line you are getting the error on, along with the error code.



You may have already mentioned this in your previous post, but what's wrong with just using the Local Security Settings?
-Security Options
-Interactive logon: Prompt user to change password before expiration : <#>days

We have over 100 laptop users, and we set this to 5 days; normal workstations to 3.

It is then their responsibility to make sure their password is changed. (Too much overhead on trying to babysit all of the laptop users)
They learn to pay attention to that message after their account gets locked out a few times.

(in reply to AzzerShaw)
 
 
Post #: 7
 
 RE: VB script to list all expired accounts in an ou - 3/10/2006 12:54:55 AM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
quote:


You may want to actually include the line you are getting the error on, along with the error code.


I thought i had!?

quote:



You may have already mentioned this in your previous post, but what's wrong with just using the Local Security Settings?
-Security Options
-Interactive logon: Prompt user to change password before expiration : <#>days



Doesnt happen if you log on with your cached profile.  I am aware this problem should land on the head of the users but as we are a pro active, we try and make everyones life easier.  This would not only prompt the user but also reduce the amount of calls our support desk recieve.  Thanks for your reply though.

< Message edited by AzzerShaw -- 3/10/2006 12:55:56 AM >

(in reply to Country73)
 
 
Post #: 8
 
 RE: VB script to list all expired accounts in an ou - 3/10/2006 1:29:32 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
I realize that you posted the message you are getting for an error, but I'm with others on this. There are only 39 lines of code in the code that you posted, so:
1)This isn't all of your code, OR
2)That is not the error message that you are getting, OR
3)Your install of WSH is crazy.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to AzzerShaw)
 
 
Post #: 9
 
 RE: VB script to list all expired accounts in an ou - 3/10/2006 1:37:38 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
Just glancing at your code, I'd say the problem may be this line:

Wscript.Echo objUser.Display Name & "    " & objUser.AccountExpirationDate

There should not be a space in the DisplayName property name.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 10
 
 RE: VB script to list all expired accounts in an ou - 3/10/2006 2:14:52 AM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
Hi, I would go with the crazy option :D

Here is the updated script. 


      

However i get back the error

Line:29
Char:10
Error:The directory property cannot be found in the cache
Code:8000500D

Any ideas?

< Message edited by AzzerShaw -- 3/10/2006 2:22:41 AM >

(in reply to ebgreen)
 
 
Post #: 11
 
 RE: VB script to list all expired accounts in an ou - 3/10/2006 2:42:43 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
Are you sure that the AccountExpirationDate is defined for all users? Can you get some other value for the users just to test that the objUser object is instantiating correctly?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to AzzerShaw)
 
 
Post #: 12
 
 RE: VB script to list all expired accounts in an ou - 3/10/2006 3:20:54 AM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
If i change this line to only do one OU (which i know has accounts due to expire in a couple of days) the script runs through fine but comes back with  the Wscript.Echo "Done with searching AD"





      


< Message edited by AzzerShaw -- 3/10/2006 3:27:48 AM >

(in reply to ebgreen)
 
 
Post #: 13
 
 RE: VB script to list all expired accounts in an ou - 3/10/2006 3:32:13 AM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
This is the orginal post.



The If..Then statement in the script below only works when the objUser.AccountExpirationDate property is specified within the true condition:
       Works:               Wscript.Echo objUser.Name & "    " & objUser.AccountExpirationDate

Any command to Echo, WriteLine, email, etc that does not contain the objUser.AccountExpirationDate property lists all enumerated objects despite failing to qualify for the conditional statement:

       Does not work:   Wscript.Echo objUser.DisplayName & "  expires soon"

The first line works ok until you try and automate notifications by sending emails or writing multiple fields to a text file and then I get a lot of extra data.

Thanks for any Help

'Script searches for expiring user accounts


      

< Message edited by AzzerShaw -- 3/10/2006 3:33:52 AM >

(in reply to AzzerShaw)
 
 
Post #: 14
 
 RE: VB script to list all expired accounts in an ou - 3/12/2006 11:37:05 PM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
I assume noones knows?  Thought it was pretty difficult, have posted a question with microsoft so hopefully i will get something back

(in reply to AzzerShaw)
 
 
Post #: 15
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VB script to list all expired accounts in an ou Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts