Function get-lastlogon

An easy function to get last logon timestamp in domain and convert it to readable time and date.

#-------------------------------------------------------------
#NAME: Get-lastlogon.ps1
#AUTHOR: Viktor Lindström
#
#COMMENTS: funtion to get last logon for a a AD-user
#-------------------------------------------------------------
 
function get-lastlogon  {
<#
.SYNOPSIS
 
Gets AD-users last logon timestamp in domain
.DESCRIPTION
Gets AD-users last logon timestamp in domain 
 
.PARAMETER filePath
 
-User
Specifies which user to check last logon timestamp
  
 
.EXAMPLE
C:\ps>get-lastlogon -user sonmat
This command will get last logon timestamp of user sonmat
 
.LINK
 
http://powerhell.nu
#>


 param
 
([parameter(mandatory)]
[string] $user)

$lastlogon = get-aduser $user | Get-ADObject -Properties lastlogontimestamp | select lastlogontimestamp
[datetime]::FromFileTime($lastlogon.lastlogontimestamp)
    }