<!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:ro
Therefore you would have to query the LastLogon on all DC's get the latest one for each computer and this is the information you need.
If you are running at Windows Server 2003 functional levelthere is a new attribute LastLogonTimestamp which is replicated to all servers.It only updates if the other DC's date for a computer object is older than 14 days so this method is quick and only accurate to around 14 days i.e. an indication if the computers have logged on recently
See the following:
http://www.rlmue
http:
and here for conversion code:
http://www.microsoft.
Main Topics
Browse All Topics





by: adamskiangelPosted on 2008-07-09 at 02:12:17ID: 21961660
# This Perl code finds inactive computer accounts
---------- ---------- ---------- ------- ---------- ---------- ---------- -------
h_secs); >bmul('10 000 000'));
nection'); mand'); n} = $connObj; ge Size'} = 1000;
P://$domai n/RootDSE" ); ngContext" );
_cont$root NC>;"; ; "; month_int) );"; \n"
inguishedN ame")->val ue,"\n";
# --------------------------
# From the book "Active Directory Cookbook" by Robbie Allen
# ISBN: 0-596-00466-4
# --------------------------
#-----------------------
# Script Configuration
#-----------------------
# Domain and container/OU to check for inactive computer accounts
my $domain = 'amer.rallencorp.com';
# set to empty string to query entire domain
my $computer_cont = 'cn=Computers,';
# Number of weeks used to find inactive computers
my $weeks_ago = 30;
#-----------------------
# End Configuration
#-----------------------
use strict;
use Win32::OLE;
$Win32::OLE::Warn = 3;
$Win32::OLE::Warn = 3;
use Math::BigInt;
# Must convert the number of seconds since $weeks_ago
# to a large integer for comparison against lastLogonTimestamp
my $sixmonth_secs = time - 60*60*24*7*$weeks_ago;
my $intObj = Math::BigInt->new($sixmont
$intObj = Math::BigInt->new($intObj-
my $sixmonth_int = Math::BigInt->new(
$intObj->badd('116 444 736 000 000 000'));
$sixmonth_int =~ s/^[+-]//;
# Setup the ADO connections
my $connObj = Win32::OLE->new('ADODB.Con
$connObj->{Provider} = "ADsDSOObject";
$connObj->Open;
my $commObj = Win32::OLE->new('ADODB.Com
$commObj->{ActiveConnectio
$commObj->Properties->{'Pa
# Grab the default root domain name
my $rootDSE = Win32::OLE->GetObject("LDA
my $rootNC = $rootDSE->Get("defaultNami
# Run ADO query and print results
my $query = "<LDAP://$domain/$computer
$query .= "(&(objectclass=computer)"
$query .= "(objectcategory=computer)
$query .= "(lastlogontimestamp<=$six
$query .= "cn,distinguishedName;";
$query .= "subtree";
$commObj->{CommandText} = $query;
my $resObj = $commObj->Execute($query);
die "Could not query $domain: ",$Win32::OLE::LastError,"
unless ref $resObj;
print "\nComputers that have been inactive for $weeks_ago weeks or more:\n";
my $total = 0;
while (!($resObj->EOF)) {
my $cn = $resObj->Fields(0)->value;
print "\t",$resObj->Fields("dist
$total++;
$resObj->MoveNext;
}
print "Total: $total\n";