Posted On May 22, 2021

PowerShell: Export Event Logs by a Certain Date Range

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Export Event Logs by a Certain Date Range
# User defined variables
$daysLimit=7
$startdate=(get-date).adddays(-$daysLimit)
$computername=$env:computername
$logName='Application'
$filterTypes='Error','Warning'
$logPath="c:\temp\eventlogs-from-$($startdate.tostring('yyyy-MM-dd'))-to-$((get-date).tostring('yyyy-MM-dd')).csv"

# Get the event logs
if(!(test-path $(split-path $logpath -parent))){$null=mkdir $(split-path $logpath -parent)}
$eventLogs = get-eventlog -ComputerName $computername -log $logName -After $startdate -EntryType $filterTypes
$eventLogs | export-csv $logPath

Leave a Reply

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

Related Post

PowerShell: Get MD5 Hashing Signature of a File

# Get-MD5-Hash.ps1# Get-FileHash (PowerShell 4.0+) replacement for Windows 2008. Forward-compatible.function getMd5{ param( $file, $md5 =…

Basic CSS: Change the Font Size of an Element

<style>.red-text {color: red;}</style><h2 class="red-text">CatPhotoApp</h2><main><p class="red-text">Click here to view more <a href="#">cat photos</a>.</p><a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A…

Linux: How to Display the SSL Certificate of a Remote Server URL

Command: server=test.kimconnect.comecho | openssl s_client -showcerts -servername $server -connect $server:443 2>/dev/null | openssl x509 -inform…