Monday 9 December 2013

Powershell script to get last login of a host in a readable format for humans


---------Start Script------------------

# Gets host and lastLogonTimestamp in UTC of specified host

# Get hostname
$hostname = Read-host "Enter a hostname"

# find the lastLogonTimestamp attribute
Get-ADComputer $hostname -Properties lastlogontimestamp |

# output hostname and timestamp in human readable format
Select-Object Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}}
pause


------------End Script---------------