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

Use PowerShell to Grant SysAdmin Role to Certain Users

$principle=$env:USERDOMAIN+'\Domain Admins' $sqlServer=$env:computername function includeSqlTools{ $ErrorActionPreference='stop' try{ $trustedPsgallery=(Get-PSRepository PSGallery).InstallationPolicy -eq 'Trusted' if(!$trustedPsgallery){ Set-PSRepository -Name PSGallery…

Windows: How to Map Network Drive for All Users of a Local Machine

# Mapping file share using legacy commands (more effective than newer PowerShell equivalents in certain…

CSS

position: absolute | relative This is referencing the first parent element. Absolute means it's removed…