Category Archives: Workstations

List Workstations and Last Logon Time from AD using Powershell

This will list computers and Last Logon Times from AD:
import-module ActiveDirectory
$dcs = Get-ADComputer -Filter { OperatingSystem -NotLike ‘*Server*’ } `
    -Properties OperatingSystem
foreach($dc in $dcs) { `
    Get-ADComputer $dc.Name -Properties lastlogontimestamp | `
    Select-Object @{n=”Computer”;e={$_.Name}}, @{Name=”Lastlogon”; `
    Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}}
}

References: http://stackoverflow.com/questions/16965355/get-last-logon-time-computer-and-username-together-with-powershell
http://blogs.technet.com/b/askds/archive/2010/02/04/inventorying-computers-with-ad-powershell.aspx