I’m new to scripting in general and have a question. I need to call a function in an in-house module that only needs to run elevated the first time. It creates an EventLogSource. Where do I need to put my elevation script block? In the script calling the function or the module itself? Here’s an example of what needs to run elevated. The function that is called runs this snippet is in a module that was built in-house.
try {
if (-not (Test-Path -Path $logSourcePath)) {
It sounds like you always need elevation to run new-eventlog if the path does not exist. Something like this should work. It will prompt UAC if it needs to create the log path.