child-shell icon indicating copy to clipboard operation
child-shell copied to clipboard

Register-ObjectEvent is not triggered

Open loukaspd opened this issue 4 years ago • 0 comments

I'm trying to run a simple script to monitor new event logs:

$eventLog = New-Object System.Diagnostics.EventLog
$eventLog.source = "Test"

Register-ObjectEvent -InputObject $eventLog -EventName EntryWritten -Action {Write-Host "Event was received!"}

Where "Test" is the name of my event log.

My js code for calling it is:

this._shell = new Shell({
          verbose: true,
          executionPolicy: 'Bypass',
          noProfile: true
        });
this._shell.on('output', data => {console.log(data)});

const file = 'D:\DWorkspace\...myscript.ps1';
this._shell.addCommand(file)
.then(() => this._shell.invoke())

I get NPS> Command invoke completed but when an event log entry is created nothing is printed. I have tested the script from classic powershell console and it worked with no problems.

Do you have any ideas, what I might be doing wrong? Thank you for your time.

loukaspd avatar Jan 15 '20 22:01 loukaspd