Windows Server - 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
ADODB.Connection
(1)
ADODB.Command
(1)
Active Directory
(1)
ADsDSOOBject
(1)
ADODB
(1)
VB
(1)
IADslargeInteger
(1)
Wscript.Shell
(1)
  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
  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
  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
  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
]
Create New Account
help
Query Active Directory Windows Server Can someone help me with printing the results of this script to a pop up box? Thanks On Error Resume Next Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection objCommand.Properties("Page Size") = 100000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE Do Until objRecordSet.EOF wscript.Echo objRecordSet.Fields("samaccountname").Value objRecordSet.MoveNext Loop Windows Server Active Directory Discussions ADODB.Connection (1) ADODB.Command (1) Active Directory (1) ADsDSOObject (1) ADODB (1) ObjRecordSet.MoveFirst (1
ti change all SAmAccountNames to lowercase. How can I do this? Windows Server Scripting Discussions ADODB.Connection (1) ADODB.Command (1) Active Directory (1) ADsDSOObject (1) ObjUser.sAMAccountName (1) ADODB (1) SAmAccountName (1) StrDNSDomain (1) Attributes in Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strNTName Dim strDN, objUser ' Setup ADO objects. Set adoCommand = CreateObject("ADODB.Command") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" adoCommand.ActiveConnection = adoConnection ' Search entire Active
issues with the following Script: On Error Resume Next Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection objCommand.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE exist on the Set objRecordSet = objCommand.Execute line. Am I doing something wrong? Windows Server Active Directory Discussions ADODB.Connection (1) ADODB.Command (1) Active Directory (1) ADsDSOObject (1) ADODB (1) ObjRecordSet.MoveFirst (1) ObjRecordSet
users, shares, groups, printers, and total number of objects? Maybe MS Support Tools???? Windows Server Active Directory Discussions ADODB.Connection (1) ADODB.Command (1) Active Directory (1) ADsDSOObject (1) ADODB (1) StrDNSDomain (1) ObjRootDSE (1) RootDSE (1) Hi Search in MVP Directory Services I was wondering if you knew of any good beginners books for Active Directory? You can use ADO in a VBScript program to query for whatever AD objects strFilter, strAttributes Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN ' Setup ADO objects. Set adoCommand = CreateObject("ADODB.Command") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" adoCommand
then output the email addresses for those users in that group? TIA, Mike Windows Server Active Directory Discussions ADODB.Connection (1) ADODB.Command (1) Active Directory (1) ADsDSOObject (1) ADODB (1) SAMAccountName (1) StrDNSDomain (1) ObjRootDSE (1) Hyena from SystemTools cn = Test Group, ou = West, dc = MyDomain, dc = com" ' Setup ADO objects. Set adoCommand = CreateObject("ADODB.Command") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" adoCommand.ActiveConnection