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

PowerShell: Hyper-V Servers Capacity Report

Current Version: # HyperVCapacityReport.ps1 # Version 0.0.2 # Report parameters $workingDirectory='C:\scripts\googleSheets' $selectFields='node,model,os,cores,cpuUtilizationPercent,ramGb,ramUsedPercent' $domainObjects=@( @{domain='intranet.kimconnect.com';dc='lax-dc02.intranet.kimconnect.com';username='intranet\clusterReport';password=$env:clusterReportPass} @{domain='intranet.dragoncoin.com';dc='lax-dc02.intranet.dragoncoin.com';username='intranet\clusterReport';password=$env:clusterReportPass}…

PowerShell: Script to Send Emails

In the past, a simple email relay script was sufficient to spool internal messages. However,…

PowerShell: Remediate Microsoft Windows Unquoted Service Path Enumeration

Description The remote Windows host has at least one service installed that uses an unquoted…