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

Windows 10 Missing Icons Problem

This sometimes happen when a certain app takes over icons cache in Windows, such as…

PowerShell: Rebooting a List of Computers

Recommended Method to Process a List of Computers: $computernames='web01','web02','web03' restart-computer -computername $computernames -force -wait Get-WmiObject…

Discover FSMO roles

Option ExplicitDim WSHNetwork, objArgs, ADOconnObj, bstrADOQueryString, RootDom, RSObjDim FSMOobj,CompNTDS, Computer, Path, HelpTextSet WSHNetwork = CreateObject("WScript.Network")Set…