Is there a way to enumerate all user accounts in the domain that will expire
on or after Dec, 31st 2004?

Re: Expiration Date by Marty

Marty
Wed Dec 29 19:11:07 CST 2004


"D-a-n_L" <djlajoie@hotmail.com> wrote in message
news:uyg2Qyf7EHA.3840@tk2msftngp13.phx.gbl...
> Is there a way to enumerate all user accounts in the domain that will
> expire
> on or after Dec, 31st 2004?
>


This script should get you started. Note that the wording can be confusing
in the "Active Directory Users and Computers" MMC - it shows you the day
before it actually expires, sating "Account expires at the end of". So if
the account expires "at the end of" 12/31/2004, then it actually is valid on
12/31/2004 and will be expired on 1/1/2005.


Option Explicit

Dim objAccount, objDomain
Dim strDomain, datAccountExpires, datExpireFilter


strDomain = "YOURDOMAIN"
datExpireFilter = #12/31/2004#

If IsDate(datExpireFilter) <> True Then
WScript.Echo "Invalid date specified: " & datExpireFilter
WScript.Quit 1
End If


WScript.Echo vbNewLine & "Enumerating accounts in the " & strDomain & _
" that expire on or after " & datExpireFilter & vbNewLine

Set objAccount = Nothing
Set objDomain = GetObject("WinNT://" & strDomain)

For Each objAccount in objDomain
datAccountExpires = 0
' The object class can be User, Group, Computer, Schema.
If UCase(objAccount.Class) = "USER" Then
On Error Resume Next
datAccountExpires = objAccount.AccountExpirationDate
On Error GoTo 0
If IsDate(datAccountExpires) Then
If DateDiff("d", datExpireFilter, datAccountExpires) >= 0 Then
WScript.Echo objAccount.Name & " (Expires " & datAccountExpires & ")"
End If
End If
End If
Next


Set objAccount = Nothing
Set objDomain = Nothing

WScript.Quit 0




Re: Expiration Date by D-a-n_L

D-a-n_L
Sat Jan 01 12:27:47 CST 2005

Awesome, thank you!

"Marty List" <bill.gates@sun.com> wrote in message
news:33h2tcF4004otU1@individual.net...
>
> "D-a-n_L" <djlajoie@hotmail.com> wrote in message
> news:uyg2Qyf7EHA.3840@tk2msftngp13.phx.gbl...
>> Is there a way to enumerate all user accounts in the domain that will
>> expire
>> on or after Dec, 31st 2004?
>>
>
>
> This script should get you started. Note that the wording can be
> confusing in the "Active Directory Users and Computers" MMC - it shows you
> the day before it actually expires, sating "Account expires at the end
> of". So if the account expires "at the end of" 12/31/2004, then it
> actually is valid on 12/31/2004 and will be expired on 1/1/2005.
>
>
> Option Explicit
>
> Dim objAccount, objDomain
> Dim strDomain, datAccountExpires, datExpireFilter
>
>
> strDomain = "YOURDOMAIN"
> datExpireFilter = #12/31/2004#
>
> If IsDate(datExpireFilter) <> True Then
> WScript.Echo "Invalid date specified: " & datExpireFilter
> WScript.Quit 1
> End If
>
>
> WScript.Echo vbNewLine & "Enumerating accounts in the " & strDomain & _
> " that expire on or after " & datExpireFilter & vbNewLine
>
> Set objAccount = Nothing
> Set objDomain = GetObject("WinNT://" & strDomain)
>
> For Each objAccount in objDomain
> datAccountExpires = 0
> ' The object class can be User, Group, Computer, Schema.
> If UCase(objAccount.Class) = "USER" Then
> On Error Resume Next
> datAccountExpires = objAccount.AccountExpirationDate
> On Error GoTo 0
> If IsDate(datAccountExpires) Then
> If DateDiff("d", datExpireFilter, datAccountExpires) >= 0 Then
> WScript.Echo objAccount.Name & " (Expires " & datAccountExpires & ")"
> End If
> End If
> End If
> Next
>
>
> Set objAccount = Nothing
> Set objDomain = Nothing
>
> WScript.Quit 0
>
>
>