Discussion:
VB script to find expiration date
(too old to reply)
crash
2009-11-12 22:07:44 UTC
Permalink
First off I am new so if this some where else I apologies I could no
find it.
what I need to do is create a script to find the expiration date of al
users in a OU in AD accounts keep expiring and I need a list of who wil
expire when so I can extend the accounts accordingly all of my attempt
have failed dose any one have a way to do this

--
cras
-----------------------------------------------------------------------
crash's Profile: http://forums.techarena.in/members/154266.ht
View this thread: http://forums.techarena.in/server-scripting/1270498.ht

http://forums.techarena.i
Richard Mueller [MVP]
2009-11-12 23:15:52 UTC
Permalink
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
--
Al Dunbar
2009-11-13 00:39:56 UTC
Permalink
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.
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
crash
2009-11-13 22:25:34 UTC
Permalink
First off thanks for the script let me try that second off if it wher
that ez that we would just extended the accounts it would be grat
unfortunately managers dont understand that concept no matter how much
protest lo

--
cras
-----------------------------------------------------------------------
crash's Profile: http://forums.techarena.in/members/154266.ht
View this thread: http://forums.techarena.in/server-scripting/1270498.ht

http://forums.techarena.i
Al Dunbar
2009-11-14 01:00:16 UTC
Permalink
Post by crash
First off thanks for the script let me try that
The script was from Richard, the other comment from me...
Post by crash
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
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
]

Loading...