Solved

VBfScript for Identifing Inactive A/c In AD

Posted on 2009-06-29
11
250 Views
Last Modified: 2012-05-07
can you guys help me to create the VB script for identifing the Inactive A/c from Active Directory. Have testing DSquery & other tools but not 100% satisfied in terms of report. If you guys help me to create a VB script only for Identifying the inactive A/c it will be great help for me.

Thanks

Biplab
0
Comment
Question by:biplabmukherjee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 24734750

I know it's not VbScript, but it does give very pretty reports in the format of your choosing:

http://www.joeware.net/freetools/tools/oldcmp/index.htm

And despite the name it does work for User accounts as well as computers.

It shows details of every attribute which can be used to determine activity. Choices of reporting format include HTML and CSV.

Chris
0
 

Author Comment

by:biplabmukherjee
ID: 24734835
Ok can we create VB script? or Do you have any idea from where I can get this. I would like to go with VB script.
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 24735328

Which fields do you want to use for inactivity? What functional level is your domain?

Chris
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:biplabmukherjee
ID: 24735348
Domain functional level is Win2003 & inactivity interms of Users ( login & logout time )
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 24735355

Okay, then the most useful are:

lastLogon
lastLogonTimeStamp

lastLogon is accurate, but not replicated which means every DC must be queried.

lastLogonTimeStamp is replicated which makes for quick queries, but can be up to 14 days out of date.

If you're looking at inactivity in terms of months that 14 days is fairly inconsequential. Happy with lastLogonTimeStamp?

Chris
0
 

Author Comment

by:biplabmukherjee
ID: 24735368
Yes with Lastlogon TimeStamp & just for FYI I am looking for inactivity in terms of months.

Thanks
Biplab
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 24735370

Cool, okay, won't be a sec!

Chris
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 24735483

This one creates a tab delimited report file called Test.txt (REPORT_FILE; in the same folder as you run the script). It only returns accounts that haven't logged in for 90 days (INACTIVE_DAYS).

Need any changes?

Chris
Option Explicit
 
' Report File Name
Const REPORT_FILE = "Test.txt"
 
' Inactive period in days
Const INACTIVE_DAYS = 90
 
' Creating the date filter
Dim dblInt8 : dblInt8 = CDbl(DateDiff("s", CDate("01/01/1601 00:00:00"), _
  Now - INACTIVE_DAYS))
 
Dim strLdapFilter : strLdapFilter = "(&(objectCategory=person)(objectClass=user)(lastLogonTimeStamp<=" & _
  CStr(dblInt8) & "0000000))"
 
Dim objConnection : Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
 
Dim objCommand : Set objCommand = Createobject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
 
Dim objRootDSE : Set objRootDSE = GetObject("LDAP://RootDSE")
 
objCommand.CommandText = "<LDAP://" & objRootDSE.Get("defaultNamingContext") & ">;" & _
  strLdapFilter & ";name,distinguishedName,lastLogonTimeStamp;subtree"
 
Dim objRecordSet : Set objRecordSet = objCommand.Execute
 
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile(REPORT_FILE, 2, True, 0)
 
Do Until objRecordSet.EOF
  Dim objLastLogon : Set objLastLogon = objRecordSet.Fields("lastLogonTimeStamp").Value
  Dim dtmLastLogon : dtmLastLogon = _
    CDate(((objLastLogon.HighPart * (2^32) + objLastLogon.LowPart) / 864000000000) + #01/01/1601#)
 
  objFile.WriteLine objRecordSet.Fields("name").Value & vbTab & _
    objRecordSet.Fields("distinguishedName").Value & vbTab & _
    dtmLastLogon
 
  ' For debugging:
  ' WScript.Echo objRecordSet.Fields("name").Value & vbTab & _
  '   objRecordSet.Fields("distinguishedName").Value & vbTab & _
  '   dtmLastLogon
 
  objRecordSet.MoveNext
Loop

Open in new window

0
 

Author Comment

by:biplabmukherjee
ID: 24735540
Thanks Chris, I will test & will update you by tommorow.

Many Thanks,

Biplab
0
 

Author Comment

by:biplabmukherjee
ID: 24783400
sorry for the late response. Could you please provide me sample report. after running this script what output will come?

Thanks in advance

0
 

Author Comment

by:biplabmukherjee
ID: 24794332
after executing this script it would create the file but it doesn't conatin any data in it. Can you please confirm me .

Thanks,

Biplab
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question