I was getting in the habit of using the native windows eventlogs for logging script activity and output and I decided to build a simple script for handling this.
The script asks what you would like to do as soon as it is ran and steps you through the process. You must run this as administrator. I want to create a cmdlet for each process, but haven’t had the chance yet. Just wanted to share.
#Script for Creating/Deleting Eventlog/Source
Write-Host 'This script CREATES/DELETES EventLogs or can add NEW Sources to existing EventLogs'
$directive = Read-Host 'Event Log:(CREATELOG/DELETELOG/ADDSOURCE)?'
if ($directive -eq 'CREATELOG') {
$logname = Read-Host 'Log Name?'
$source = Read-Host 'Source Name?'
New-EventLog -LogName $logname -Source $source
Write-Host $logname 'with sourcename of' $source 'created'
}
if ($directive -eq 'DELETELOG') {
$logname = Read-Host 'Log Name?'
Remove-EventLog -Logname $logname
Write-Host $logname 'Deleted'
}
if ($directive -eq 'ADDSOURCE') {
$logname = Read-Host 'Log Name?'
$source = Read-Host 'Source Name?'
New-EventLog -LogName $logname -Source $source
Write-Host $source 'source added to' $logname 'log'
}