-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
603475f
commit a9a7045
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#require -version 3.0 | ||
|
||
<# | ||
.SYNOPSIS | ||
Clear all event logs | ||
#> | ||
function Clear-EventLogs { | ||
Get-EventLog * | % { Clear-EventLog $_.Log } | ||
|
||
#Clear this one again as it accumulates clearing events from previous step | ||
Clear-EventLog System | ||
Get-EventLog * | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Get latest event logs across all event logs | ||
.Example | ||
logs Error,Warning -Newest 5 | ||
#> | ||
function Get-EventLogs{ | ||
param( | ||
[ValidateSet('Error', 'Information', 'Warning', '*')] | ||
[string[]] $EntryType = 'Error', | ||
|
||
[int] $Newest=1000, | ||
|
||
[switch] $Raw | ||
) | ||
$r = @() | ||
|
||
if ($EntryType -eq '*') { $EntryType = 'Error', 'Information', 'Warning' } | ||
Get-EventLog * | % Log | % { | ||
$log = $_ | ||
try { | ||
$r += Get-EventLog -Log $log -Newest $Newest -EntryType $EntryType -ea 0 | ||
} | ||
catch { Write-Warning "$log - $_" } | ||
} | ||
$r = $r | sort TimeWritten -Descending | ||
if ($Raw) {$r} else { $r | select Source, TimeWritten, Message } | ||
} | ||
|
||
sal logs Get-EventLogs | ||
sal clearlogs Clear-EventLogs |