Re: Another Newbie




"gchalfont@xxxxxxxxxxxxxxxx"
<gchalfont@xxxxxxxxxxxxxxxx@discussions.microsoft.com> wrote in message
news:EF11E564-B1B3-4AF6-95C6-E408C2CA2955@xxxxxxxxxxxxxxxx
Hi all.. please bear with me as I'm extremely green when it comes to
scripting. I need a script that will give me a list of all users who's
passwords are set to never expire in Active Directory. I'm in a server
2003
environment. Domain=thomasnelson.com All users are in an OU labeled
UsersOU. Any help would be appreciated. Also, do I run the vbs script
from
my local machine, or do I need to do this on the domain controller???

The best way to query users is with ADO. The following filters on users that
have password never expires set. It outputs the NT name and Distinguished
Names of these users. Modify the value assigned to strOU for your OU:
======
Option Explicit

Dim adoCommand, adoConnection
Dim strBase, strFilter, strAttributes, strQuery, adoRecordset
Dim strDN, strNTName, strOU

' Specify Distinguished Name of OU.
strOU = "ou=MyOU,dc=MyDomain,dc=com"

' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

' Specify base of search as the OU.
strBase = "<LDAP://"; & strOU & ">"

' Filter on user objects that have password never expires flag set.
strFilter = "(&(objectCategory=person)(objectClass=user)" _
& "(userAccountControl:1.2.840.113556.1.4.803:=65536))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName,sAMAccountName"

' Query Active Directory and return recordset.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
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
' Retrieve the attribute values.
strDN = adoRecordset.Fields("distinguishedName").Value
strNTName = adoRecordset.Fields("sAMAccountName").Value
Wscript.Echo strNTName & ", " & strDN
adoRecordset.MoveNext
Loop

' Clean up.
adoRecordset.Close
adoConnection.Close
===========
The script can be run at a command prompt with the cscript host. Assuming
the code is in a file called PWNeverExp.vbs in the current directory, the
output can be redirected to a text file with a command similar to:

cscript //nologo PWNeverExp.vbs > report.txt

The //nologo option suppresses logo info.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


.



Relevant Pages

  • Re: instituting ad password policy
    ... Either script this or do it manually. ... ' Use ADO to search Active Directory. ... ' Filter on user objects that have password never expires flag set. ... ' Comma delimited list of attribute values to retrieve. ...
    (microsoft.public.windows.server.active_directory)
  • Re: Need assistance badly!
    ... I have tried cobbling together a script that does this, ... I would use ADO in a VBScript program to retrieve all users with the ... Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN ... adoConnection.Open "Active Directory Provider" ...
    (microsoft.public.scripting.vbscript)
  • Re: Operations Masters
    ... Run diagnostics against your Active Directory domain. ... Run dcdiag, netdiag and repadmin in verbose mode. ... If you download a gui script I wrote it should be simple to set and run ...
    (microsoft.public.windows.server.active_directory)
  • Re: Disable/Delete unused workstations
    ... This script will remove inactive machine accounts in Active Directory ... > is there a way to automatically disable or delete workstations not used in ...
    (microsoft.public.win2000.group_policy)
  • Error "An invalid directory pathname was passed"
    ... I am trying to use a vb script to add groups to a Active Directory ... This is the first script I have tried to write, so I am new at this. ... Dim strOU, strNewGroup, strNewGroupLong, strDNSDomain, objFSO, ... Dim strGuyGp, strGPType, arrGroups ...
    (microsoft.public.vb.syntax)

Loading