Skip to content

Instantly share code, notes, and snippets.

@peaeater
Created June 19, 2014 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peaeater/8be00dbcf2b0a4a0f28e to your computer and use it in GitHub Desktop.
Save peaeater/8be00dbcf2b0a4a0f28e to your computer and use it in GitHub Desktop.
Removes a source value from Windows Application Event Log (careful!). Requires admin privileges and warns user if elevation is required.
<#
Remove log source from Application Event Log - requires ADMIN PRIVILEGES
Peter Tyrrell
#>
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0)]
[string]$logsrc
)
# 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 {
[System.Diagnostics.EventLog]::DeleteEventSource($logsrc)
Write-Host ("INFO Deleted '{0}'' from Application Event Log." -f $logsrc)
}
catch {
Write-Host ("INFO The source '{0}' is not registered on the machine." -f $logsrc)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment