First off I am new so if this some where else I apologies I could not
find it.
what I need to do is create a script to find the expiration date of all
users in a OU in AD accounts keep expiring and I need a list of who will
expire when so I can extend the accounts accordingly all of my attempts
have failed dose any one have a way to do this.
--
crash
------------------------------------------------------------------------
crash's Profile: http://forums.techarena.in/members/154266.htm
View this thread: http://forums.techarena.in/server-scripting/1270498.htm
http://forums.techarena.in
Below is an example VBScript program that uses ADO to output user names and
the account expiration date (in local time) for all users in a specified OU:
========
Option Explicit
Dim adoConnection, adoCommand
Dim strFilter, strQuery, adoRecordset, strBase, strAttributes
Dim strDN, objShell, lngBiasKey, lngBias
Dim lngDate, objDate, dtmAcctExp, k, strOU
' Specify the Distinguished Name of the OU.
strOU = "ou=Sales,ou=West,dc=MyDomain,dc=com"
strBase = "<LDAP://" & strOU & ">"
' Obtain local time zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _
& "TimeZoneInformation\ActiveTimeBias")
If (UCase(TypeName(lngBiasKey)) = "LONG") Then
lngBias = lngBiasKey
ElseIf (UCase(TypeName(lngBiasKey)) = "VARIANT()") Then
lngBias = 0
For k = 0 To UBound(lngBiasKey)
lngBias = lngBias + (lngBiasKey(k) * 256^k)
Next
End If
' Use ADO to search the domain.
Set adoConnection = CreateObject("ADODB.Connection")
Set adoCommand = CreateObject("ADODB.Command")
adoConnection.Provider = "ADsDSOOBject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection
' Filter on all user objects in base.
strFilter = "(&(objectCategory=person)(objectClass=user))"
' Comma delimited list of attributes to retrieve.
strAttributes = "distinguishedName,accountExpires"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
' Enumerate the recordset.
Do Until adoRecordset.EOF
strDN = adoRecordset.Fields("distinguishedName").Value
lngDate = adoRecordset.Fields("accountExpires")
Set objDate = lngDate
dtmAcctExp = Integer8Date(objDate, lngBias)
Wscript.Echo strDN & ";" & dtmAcctExp
adoRecordset.MoveNext
Loop
adoRecordset.Close
' Clean up.
adoConnection.Close
Function Integer8Date(ByVal objDate, ByVal lngBias)
' Function to convert Integer8 (64-bit) value to a date, adjusted for
' local time zone bias.
Dim lngAdjust, lngDate, lngHigh, lngLow
lngAdjust = lngBias
lngHigh = objDate.HighPart
lngLow = objdate.LowPart
' Account for bug in IADslargeInteger property methods.
If (lngLow < 0) Then
lngHigh = lngHigh + 1
End If
If (lngHigh = 0) And (lngLow = 0) Then
lngAdjust = 0
End If
lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow) / 600000000 - lngAdjust) / 1440
' Trap error if lngDate is ridiculously huge.
On Error Resume Next
Integer8Date = CDate(lngDate)
If (Err.Number <> 0) Then
On Error GoTo 0
Integer8Date = #1/1/1601#
End If
On Error GoTo 0
End Function
======
The date "1/1/1601" means never.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--