last logon time script

  • Follow


I am trying to find a script that can produce a list of users' last logon 
time.
There is a vbs which only applys windows 2003 functional level AD, but our 
AD is still mixed or interum.
thanks in advance! 


0
Reply tree 12/8/2009 8:57:29 AM

I'm using hyena to do the same thing you want... but i can take a lot of 
information and export everything to excel.


"tree leafs" <treeleafs@hotmail.com> escreveu na mensagem 
news:eVnf6R%23dKHA.2184@TK2MSFTNGP04.phx.gbl...
>I am trying to find a script that can produce a list of users' last logon 
>time.
> There is a vbs which only applys windows 2003 functional level AD, but our 
> AD is still mixed or interum.
> thanks in advance!
> 


0
Reply Luiz 12/8/2009 4:25:27 PM


"tree leafs" <treeleafs@hotmail.com> wrote in message 
news:eVnf6R%23dKHA.2184@TK2MSFTNGP04.phx.gbl...
>I am trying to find a script that can produce a list of users' last logon 
>time.
> There is a vbs which only applys windows 2003 functional level AD, but our 
> AD is still mixed or interum.
> thanks in advance!
>

You can use the first program linked on this page:

http://www.rlmueller.net/Last%20Logon.htm

-- 
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
-- 


0
Reply Richard 12/8/2009 6:28:40 PM

thanks for all.

"tree leafs" <treeleafs@hotmail.com> wrote in message 
news:eVnf6R%23dKHA.2184@TK2MSFTNGP04.phx.gbl...
>I am trying to find a script that can produce a list of users' last logon 
>time.
> There is a vbs which only applys windows 2003 functional level AD, but our 
> AD is still mixed or interum.
> thanks in advance!
> 


0
Reply tree 12/9/2009 1:46:35 AM

hi 
here is apowershell script
it require only powershell V1
this script connects to AD and calculates the last logon time for the users you specify and outputs them into a CSV file with one column for the displayname and other for lastlogontime

# ==============================================================================================
#  
# Script Name: get User and last logon time into a CSV file
# 
# AUTHOR: Mohamed Garrana , 
# DATE  : 4/13/2010
# 
# COMMENT: 
# 
# ==============================================================================================

function connect{

$ADpath = "LDAP://OU=Users,OU=IT Department,DC=domain,DC=win2k,DC=dom" #set your ldap path to your domain or certian OU 
$searcher = New-Object DirectoryServices.DirectorySearcher
$RootSearch = New-Object directoryservices.directoryentry $ADpath
$searcher.searchroot = $RootSearch
$searcher.filter = "(objectClass=user)"
$allusers = $searcher.findall()
foreach ($user in $allusers) { get-lastlogontime }	
}
function get-lastlogontime {
	BEGIN { }
	PROCESS  {
	#Write-Host $user.Properties.Displayname[0]
	try {
	$name = $user.Properties.displayname[0] 
	$adlastlogon=$user.Properties.lastlogon[0]
	}
	Catch {
	Write-Host -ForegroundColor Red "   <<< WHoops ... >>>  $name : Error reading a required property from the AD User object, execution will continue anyway ;)"
		continue
		}
	finally {
	[datetime]$initialdate="01/01/1601" #microsoft date used to calculate lastlogon
	$lastlogon = $initialdate.Addseconds(($adlastlogon*1e-7)) #nano seconds interval + initial date
	$AdUser = New-Object psobject 
	$AdUser | Add-Member NoteProperty DisplayName ($name)
	$AdUser | Add-Member NoteProperty LastLogon ($lastlogon)
	Write-Output $AdUser
	}
	} 
	END{}
}
$csvfile="C:\test\userlastlogon.csv" #set the location of your output file
connect |  Export-Csv $csvfile 



tree leafs wrote:

last logon time script
08-Dec-09

I am trying to find a script that can produce a list of users' last logon
time.
There is a vbs which only applys windows 2003 functional level AD, but our
AD is still mixed or interum.
thanks in advance!

Previous Posts In This Thread:

On Tuesday, December 08, 2009 3:57 AM
tree leafs wrote:

last logon time script
I am trying to find a script that can produce a list of users' last logon
time.
There is a vbs which only applys windows 2003 functional level AD, but our
AD is still mixed or interum.
thanks in advance!

On Tuesday, December 08, 2009 11:25 AM
Luiz Carlos wrote:

I am using hyena to do the same thing you want...
I am using hyena to do the same thing you want... but i can take a lot of
information and export everything to excel.

On Tuesday, December 08, 2009 1:28 PM
Richard Mueller [MVP] wrote:

You can use the first program linked on this page:http://www.rlmueller.
You can use the first program linked on this page:

http://www.rlmueller.net/Last%20Logon.htm

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

On Tuesday, December 08, 2009 8:46 PM
tree leafs wrote:

thanks for all.
thanks for all.


Submitted via EggHeadCafe - Software Developer Portal of Choice 
IIS 7.0 Extensionless UrlRewriting (Short urls)
http://www.eggheadcafe.com/tutorials/aspnet/6592d2d4-bbf4-4ecd-93df-52898c6aa5d7/iis-70-extensionless-url.aspx
0
Reply Mohamed 4/13/2010 12:55:54 PM

This is a VBScript group. For powershell
try here:

microsoft.public.windows.powershell



0
Reply Mayayana 4/13/2010 1:28:04 PM

I believe this script will only work if there is one Domain Controller (DC) 
in the domain. The lastLogon attribute is not replicated, so a different 
value is saved on each DC. You must query every DC in the domain and retain 
the largest value for each user. I don't code in PowerShell, so correct me 
if I am wrong, but I don't see where the script below does this.

-- 
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"Mohamed Garrana" wrote in message news:201041385553mgarrana@hotmail.com...
> hi
> here is apowershell script
> it require only powershell V1
> this script connects to AD and calculates the last logon time for the 
> users you specify and outputs them into a CSV file with one column for the 
> displayname and other for lastlogontime
>
> # 
> ==============================================================================================
> #
> # Script Name: get User and last logon time into a CSV file
> #
> # AUTHOR: Mohamed Garrana ,
> # DATE  : 4/13/2010
> #
> # COMMENT:
> #
> # 
> ==============================================================================================
>
> function connect{
>
> $ADpath = "LDAP://OU=Users,OU=IT Department,DC=domain,DC=win2k,DC=dom" 
> #set your ldap path to your domain or certian OU
> $searcher = New-Object DirectoryServices.DirectorySearcher
> $RootSearch = New-Object directoryservices.directoryentry $ADpath
> $searcher.searchroot = $RootSearch
> $searcher.filter = "(objectClass=user)"
> $allusers = $searcher.findall()
> foreach ($user in $allusers) { get-lastlogontime }
> }
> function get-lastlogontime {
> BEGIN { }
> PROCESS  {
> #Write-Host $user.Properties.Displayname[0]
> try {
> $name = $user.Properties.displayname[0]
> $adlastlogon=$user.Properties.lastlogon[0]
> }
> Catch {
> Write-Host -ForegroundColor Red "   <<< WHoops ... >>>  $name : Error 
> reading a required property from the AD User object, execution will 
> continue anyway ;)"
> continue
> }
> finally {
> [datetime]$initialdate="01/01/1601" #microsoft date used to calculate 
> lastlogon
> $lastlogon = $initialdate.Addseconds(($adlastlogon*1e-7)) #nano seconds 
> interval + initial date
> $AdUser = New-Object psobject
> $AdUser | Add-Member NoteProperty DisplayName ($name)
> $AdUser | Add-Member NoteProperty LastLogon ($lastlogon)
> Write-Output $AdUser
> }
> }
> END{}
> }
> $csvfile="C:\test\userlastlogon.csv" #set the location of your output file
> connect |  Export-Csv $csvfile
>
>
>
> tree leafs wrote:
>
> last logon time script
> 08-Dec-09
>
> I am trying to find a script that can produce a list of users' last logon
> time.
> There is a vbs which only applys windows 2003 functional level AD, but our
> AD is still mixed or interum.
> thanks in advance!
>
> Previous Posts In This Thread:
>
> On Tuesday, December 08, 2009 3:57 AM
> tree leafs wrote:
>
> last logon time script
> I am trying to find a script that can produce a list of users' last logon
> time.
> There is a vbs which only applys windows 2003 functional level AD, but our
> AD is still mixed or interum.
> thanks in advance!
>
> On Tuesday, December 08, 2009 11:25 AM
> Luiz Carlos wrote:
>
> I am using hyena to do the same thing you want...
> I am using hyena to do the same thing you want... but i can take a lot of
> information and export everything to excel.
>
> On Tuesday, December 08, 2009 1:28 PM
> Richard Mueller [MVP] wrote:
>
> You can use the first program linked on this page:http://www.rlmueller.
> You can use the first program linked on this page:
>
> http://www.rlmueller.net/Last%20Logon.htm
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
> On Tuesday, December 08, 2009 8:46 PM
> tree leafs wrote:
>
> thanks for all.
> thanks for all.
>
>
> Submitted via EggHeadCafe - Software Developer Portal of Choice
> IIS 7.0 Extensionless UrlRewriting (Short urls)
> http://www.eggheadcafe.com/tutorials/aspnet/6592d2d4-bbf4-4ecd-93df-52898c6aa5d7/iis-70-extensionless-url.aspx 


0
Reply Richard 4/13/2010 2:49:36 PM

6 Replies
761 Views

(page loaded in 0.388 seconds)


Reply: