Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accountExpires

Status
Not open for further replies.

krinid

Programmer
Jun 10, 2003
356
0
0
CA
I'm trying to reference the 'accountExpires' property of an account and am getting the following error:
Active Directory: The directory property cannot be found in the cache.

I can access the 'AccountExpirationDate' property, but not 'AccountExpires' property. Does anyone know why?

The code is as follows:
Code:
Set objUser = GetObject ("LDAP://...")

' the below 2 lines work fine
WScript.Echo objUser.AccountExpirationDate
objUser.AccountExpirationDate = "2008/11/11"

' the below 3 lines all generate the above error
WScript.echo objUser.Get "accountExpires"
objUser.Put "accountExpires",0 ' does not expire
objUser.Put "accountExpires", "2008/11/11"
 
That almost always means that the AD property you are trying to access is not properly populated for the AD object that you are trying to access.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Do you mean that that property isn't populated in my AD schema? What's the best way to verify?
 
I'm not an AD admin, I am simply at the mercy of them here. Whe I want to figure something out like this I start by looking at what I can see in the AD Users and computers MMC plugin.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Account-Expires
The date when the account expires. This value represents the number of 100 nanosecond intervals since January 1, 1601 (UTC). A value of 0 or 0x7FFFFFFFFFFFFFFF (9223372036854775807) indicates that the account never expires.

I think using accountExpirationDate with a good old fashion date/time format would be several times easier than having to work with the 100 nanosecond intervals.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
You can retrieve the expiration date as follows:

Code:
On Error Resume Next

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

dtmAccountExpiration = objUser.AccountExpirationDate 
 
If Err.Number = -2147467259 Or dtmAccountExpiration = "1/1/1970" Then
    WScript.Echo "No account expiration date specified"
Else
    WScript.Echo "Account expiration date: " & objUser.AccountExpirationDate
End If

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
tsuji,
Will the following code (extracted from the link you provided) run the same on all PCs, independent of the local date format?

Code:
If Err.Number = -2147467259 OR dtmAccountExpiration = #1/1/1970# Then
    WScript.Echo "This account has no expiration date."
Else
    WScript.Echo "Account expiration date: " & objUser.AccountExpirationDate
End If

What I'm concerned about is that if I run this on different PC with different time formats, the results will be different, because #1/1/1970# will be interpreted differently.
 
It would be quite independent of the local, in fact, you can even do #2007/1/1# (yyyy/m/d) for script approach. But you are still feeling unsafe, you can always resort to dateserial function:
[tt] dtmAccountExpiration=dateserial(1970,1,1)[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top