Posted On March 29, 2019

Last Logon Dates of List of AD Accounts

kimconnect 0 comments
blog.KimConnect.com >> Codes , Windows >> 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 *

Related Post

WinRM and Trusted Hosts for Non-Domain Computers

Error: [TESTWINDOWS] Connecting to remote server TESTWINDOWS failed with the following error message : Access…

PowerShell: Creating Active Directory Accounts from CSV File

# User-input Variables $csvFile='C:\Users\rambo\Desktop\newUsers-finalized.csv' $newOu='CN=Users,DC=kimconnect,DC=com' $newCompany='KimConnect.com' $logFile="c:\temp\createActiveDirectoryAccounts-$(get-date -f yyyy-mm-dd-hh-mm-ss).txt" function createActiveDirectoryAccounts{ param( $csvFile, $newOu, $newCompany,…

How To Quickly Search a User in Active Directory by Matching Email

This one liner would do the trick: Get-ADUser -Filter {EmailAddress -eq '[email protected]'} PS C:\Windows\system32> Get-ADUser…