I am creating a new EventLog EventSource, and I use my own custom set of categories.
I currently do this in C# code with the following:
var eventSourceData = new EventSourceCreationData(sourceName, logName)
{
CategoryCount = AllCategories.Count(),
CategoryResourceFile = resourceFilePath,
ParameterResourceFile = resourceFilePath,
MessageResourceFile = resourceFilePath
};
EventLog.CreateEventSource(eventSourceData);
I have now converted this to a powershell script like this:
New-eventlog -logname $Log -ComputerName $ComputerName -Source $Source -CategoryResourceFile $categoryDllPath -MessageResourceFile $categoryDllPath -ErrorVariable Err -CategoryCount 20
Notr -CategoryCount 20 at the end, my script fails on this argument saying it is not a valid parameter. (Which it seems not to be)
So my question is, using Powershell how can I provide the CategoryCount so that the logging works correctly?
Thanks so much.
The error message is A parameter cannot be found that matches parameter name 'CategoryCount'.
As far as I can see, New-EventLog
doesn't support CategoryCount.
But you can still use .NET classes directly in Powershell, so something like this should work:
$eventSourceData = new-object System.Diagnostics.EventSourceCreationData("$SourceName", "$logName")
$eventSourceData.CategoryCount = 20
$eventSourceData.CategoryResourceFile = $CategoryDllPath
$eventSourceData.MessageResourceFile = $CategoryDllPath
If (![System.Diagnostics.EventLog]::SourceExists($eventSourceData.Source))
{
[System.Diagnostics.EventLog]::CreateEventSource($eventSourceData)
}