From: Mohamed on 13 Apr 2010 08:55 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
From: Mayayana on 13 Apr 2010 09:28 This is a VBScript group. For powershell try here: microsoft.public.windows.powershell
From: Richard Mueller [MVP] on 13 Apr 2010 10:49 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(a)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
|
Pages: 1 Prev: working with exceptions Next: Window 7 Active Directory and VbsEdit |