PowerShell: Get LastLogon Information of Computer Objects

$computernames=@(
    'COMPUTER1',
'COMPUTER2'
)

$computerLastLogon=foreach($computerName in $computernames){
    get-adcomputer $computerName -Properties LastLogon|select Name,@{Name='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}}
}
$computerLastLogon|sort -Property LastLogon

Leave a Reply

Your email address will not be published. Required fields are marked *