Created
June 19, 2014 00:30
-
-
Save peaeater/c3f0bd2357af8667bb50 to your computer and use it in GitHub Desktop.
Adds supplied source value to the Windows Application Event Log. Requires admin privileges and will warn the user if elevation is required.
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
<# | |
Add log source to Application Event Log if not already there - REQUIRES ADMIN privileges | |
Peter Tyrrell | |
#> | |
param( | |
[Parameter(Mandatory=$false,ValueFromPipeline=$true,Position=0)] | |
[string]$logsrc = "Andi Solr Update" | |
) | |
# check for admin | |
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { | |
Write-Warning ("You do not have admin privileges. Re-run this script as an administrator.") | |
break | |
} | |
try { | |
if (-not [System.Diagnostics.EventLog]::SourceExists($logsrc)) { | |
[System.Diagnostics.EventLog]::CreateEventSource($logsrc, "Application") | |
Write-Host ("INFO Source '{0}' added to Application Event Log." -f $logsrc) | |
} | |
else { | |
Write-Host ("INFO {0} is already a source in Application Event Log." -f $logsrc) | |
} | |
} | |
catch { | |
throw | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment