Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress errors that may occur when clearing event logs #146

Merged
merged 1 commit into from Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 6 additions & 9 deletions gce_base.psm1
Expand Up @@ -84,15 +84,12 @@ function Clear-EventLogs {
clean the eventlogs for a machine.
#>

try {
Write-Log 'Clearing events in EventViewer.'
Get-WinEvent -ComputerName $global:hostname -ListLog * |
Where-Object {($_.IsEnabled -eq 'True') -and ($_.RecordCount -gt 0)} |
ForEach-Object {[System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog($_.LogName)}
}
catch {
_PrintError
}
Write-Log 'Clearing events in EventViewer.'
Get-WinEvent -ListLog * |
Where-Object {($_.IsEnabled -eq 'True') -and ($_.RecordCount -gt 0)} |
ForEach-Object {
try{[System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog($_.LogName)}catch{}
}
}


Expand Down
2 changes: 1 addition & 1 deletion google-compute-engine-powershell.goospec
@@ -1,6 +1,6 @@
{
"name": "google-compute-engine-powershell",
"version": "1.1.0@4",
"version": "1.1.1@4",
"arch": "noarch",
"authors": "Google Inc.",
"license": "http://www.apache.org/licenses/LICENSE-2.0",
Expand Down