Skip to content

Instantly share code, notes, and snippets.

@bill-long
Last active August 9, 2016 08:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bill-long/1d94a18fbaaa33ef912e to your computer and use it in GitHub Desktop.
Save bill-long/1d94a18fbaaa33ef912e to your computer and use it in GitHub Desktop.
# Save-AllExchangeLogs.ps1
$timeString = (Get-Date).ToString("yyyyMMddHHmm")
$machineName = [Environment]::MachineName
$targetFolder = "$home\desktop\ExchangeLogs-$machineName-$timeString"
md $targetFolder | Out-Null
"Saving $targetFolder\Application.evtx..."
wevtutil epl Application "$targetFolder\Application.evtx"
"Saving $targetFolder\System.evtx..."
wevtutil epl System "$targetFolder\System.evtx"
$exchangeLogs = wevtutil el | WHERE { $_.Contains("Exchange") }
foreach ($log in $exchangeLogs)
{
$targetFile = Join-Path $targetFolder "$log.evtx"
"Saving $targetFile..."
$dir = [IO.Path]::GetDirectoryName($targetFile)
if (!(Test-Path $dir)) { New-Item -ItemType Directory $dir | Out-Null }
wevtutil epl $log $targetFile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment