Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
VB script to find expiration date
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
crash  
View profile  
 More options Nov 12 2009, 10:07 pm
Newsgroups: microsoft.public.windows.server.scripting
From: crash <crash.41k...@DoNotSpam.com>
Date: Fri, 13 Nov 2009 03:37:44 +0530
Local: Thurs, Nov 12 2009 10:07 pm
Subject: VB script to find expiration date

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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mueller [MVP]  
View profile  
 More options Nov 12 2009, 11:15 pm
Newsgroups: microsoft.public.windows.server.scripting
From: "Richard Mueller [MVP]" <rlmueller-nos...@ameritech.nospam.net>
Date: Thu, 12 Nov 2009 17:15:52 -0600
Local: Thurs, Nov 12 2009 11:15 pm
Subject: Re: VB script to find expiration date

"crash" <crash.41k...@DoNotSpam.com> wrote in message

news:crash.41k73c@DoNotSpam.com...

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
--


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Al Dunbar  
View profile  
 More options Nov 13 2009, 12:39 am
Newsgroups: microsoft.public.windows.server.scripting
From: "Al Dunbar" <aland...@hotmail.com>
Date: Thu, 12 Nov 2009 17:39:56 -0700
Local: Fri, Nov 13 2009 12:39 am
Subject: Re: VB script to find expiration date

"crash" <crash.41k...@DoNotSpam.com> wrote in message

news:crash.41k73c@DoNotSpam.com...

> 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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
crash  
View profile  
 More options Nov 13 2009, 10:25 pm
Newsgroups: microsoft.public.windows.server.scripting
From: crash <crash.41m...@DoNotSpam.com>
Date: Sat, 14 Nov 2009 03:55:34 +0530
Local: Fri, Nov 13 2009 10:25 pm
Subject: Re: VB script to find expiration date

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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Al Dunbar  
View profile  
 More options Nov 14 2009, 1:00 am
Newsgroups: microsoft.public.windows.server.scripting
From: "Al Dunbar" <aland...@hotmail.com>
Date: Fri, 13 Nov 2009 18:00:16 -0700
Local: Sat, Nov 14 2009 1:00 am
Subject: Re: VB script to find expiration date

"crash" <crash.41m...@DoNotSpam.com> wrote in message

news:crash.41m4jc@DoNotSpam.com...

> First off thanks for the script let me try that

The script was from Richard, the other comment from me...

>    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
]


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google