Re: Script to find user accounts where "Password never Expires"
From: Richard Mueller [MVP] (rlmueller-NOSPAM_at_ameritech.NOSPAM.net)
Date: 03/31/04
- Next message: Torgeir Bakken \(MVP\): "Re: Script to get installed software and server applications on remote servers"
- Previous message: Torgeir Bakken \(MVP\): "Re: Please Recommend a wscript book...."
- In reply to: Richard Rekos: "Script to find user accounts where "Password never Expires""
- Next in thread: Richard Rekos: "Re: Script to find user accounts where "Password never Expires""
- Reply: Richard Rekos: "Re: Script to find user accounts where "Password never Expires""
- Reply: Richard Rekos: "Re: Script to find user accounts where "Password never Expires""
- Reply: Microsoft: "Re: Script to find user accounts where "Password never Expires""
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 31 Mar 2004 16:14:01 -0600
Richard Rekos wrote:
> Using the following script, I can determine if a single user has "password
never expires" enabled or not. Does anyone have a script that can do this
for ALL users in a particular OU? Thanks in advance!
>
> Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
> Set objUser = GetObject("LDAP://CN=rich,OU=us,DC=xyz,DC=com")
> intUserAccountControl = objUser.Get("userAccountControl")
> If intUserAccountControl And ADS_UF_DONT_EXPIRE_PASSWD Then
> WScript.Echo "The password does not expire."
> WScript.Quit
> Else
> WScript.Echo "The password expires."
> End If
>
Hi,
Two ways to tackle this. First, you can bind to the OU, filter on user
objects, then enumerate the users. Note that this will only handle users
that are actually in the OU, not those in sub OU's (unless you code a
recursive subroutine). For example:
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
Set objOU = GetObject("LDAP://ou=us,dc=xyz,dc=com")
objOU.Filter = Array("user")
For Each objUser In objOU
intUserAccountControl = objUesr.Get("userAccountControl")
If (intUserAccountControl And ADS_UF_DONT_EXPIRE_PASSWD) <> 0 Then
Wscript.Echo "Password never expires for user " & objUser.sAMAccountName
Else
Wscript.Echo "Password expires for user " & objUser.sAMAccountName
End If
Next
A more powerful method is to use ADO. You can retrieve just the users whose
password never expires. The code below will find all users whose password
does not expire in the OU and in any sub OU's:
Option Explicit
Dim objCommand, objConnection
Dim strBase, strFilter, strAttributes, strQuery, objRecordSet
Dim strNTName
' Use ADO to search Active Directory.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
' Specify base of search (starting point).
strBase = "<LDAP://ou=us,dc=xyz,dc=com>"
' Filter on users with ADS_UF_EXPIRE_PASSWD bit of userAccountControl set.
strFilter = "(&(objectCategory=person)(objectClass=user)" _
& "(userAccountControl:1.2.840.113556.1.4.803:=65536))"
' Retrieve sAMAccount attribute (comma delimited list of attributes).
strAttributes = "sAMAccountName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
' Enumerate results found.
Do Until objRecordSet.EOF
strNTName = objRecordSet.Fields("sAMAccountName")
Wscript.Echo strNTName
objRecordSet.MoveNext
Loop
' Clean up.
objConnection.Close
Set objRootDSE = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing
-- Richard Microsoft MVP Scripting and ADSI HilltopLab web site - http://www.rlmueller.net --
- Next message: Torgeir Bakken \(MVP\): "Re: Script to get installed software and server applications on remote servers"
- Previous message: Torgeir Bakken \(MVP\): "Re: Please Recommend a wscript book...."
- In reply to: Richard Rekos: "Script to find user accounts where "Password never Expires""
- Next in thread: Richard Rekos: "Re: Script to find user accounts where "Password never Expires""
- Reply: Richard Rekos: "Re: Script to find user accounts where "Password never Expires""
- Reply: Richard Rekos: "Re: Script to find user accounts where "Password never Expires""
- Reply: Microsoft: "Re: Script to find user accounts where "Password never Expires""
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|