ADODB.Connection
(1)
ADODB.Command
(1)
Active Directory
(1)
ADsDSOOBject
(1)
ADODB
(1)
VB
(1)
IADslargeInteger
(1)
Wscript.Shell
(1)

VB script to find expiration date

Asked By crash
12-Nov-09 05:07 PM
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 andthe

Richard Mueller [MVP] replied to crash
12-Nov-09 06:15 PM
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

If you are simply going to extend the expiry date in advance, why do youeven

Al Dunbar replied to crash
12-Nov-09 07:39 PM
If you are simply going to extend the expiry date in advance, why do you
even bother setting an expiry in the first place?

/Al

First off thanks for the script let me try that second off if it wherethat ez

crash replied to Al Dunbar
13-Nov-09 05:25 PM
First off thanks for the script let me try that second off if it where
that ez that we would just extended the accounts it would be grate
unfortunately managers dont understand that concept no matter how much I
protest lol


--
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
The script was from Richard, the other comment from me...
Al Dunbar replied to crash
13-Nov-09 08:00 PM
The script was from Richard, the other comment from me...


If the managers think you need to set expiry on the accounts, why not just
let them expire? After all, that is the purpose of account expiry.

/Al
]
Post Question To EggHeadCafe