Last Logon Dates of List of AD Accounts

import-module activedirectory
$output=""

Get-Content C:\Users\kimconnect\Desktop\targetAccounts.txt | Foreach-Object -Process{
#  cast an array object as string before using string operations
  $output+=$_+": "+([string](Get-ADUser $_ -Properties * | Select lastLogonDate) -replace "@{lastLogonDate=*" -replace "}") + "`n"
}
$output

Leave a Reply

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