PowerShell / WindowsCompatibility

Module that allows Windows PowerShell Modules to be used from PSCore6
Other
137 stars 33 forks source link

New-EventLog didn't output the error message in powershell 6.1 #48

Closed chucklu closed 5 years ago

chucklu commented 5 years ago

Hi @SteveL-MSFT @BrucePay , After I installed this module, I can use command in powershell 6.1 Get-EventLog -Newest 5 -LogName "Application" . But when I use command in powershell 6.1 New-EventLog -Source "SupperSocketService" -LogName "TestLog" -MessageResourceFile "C:\Test\TestApp.dll", nothing happened. No error info and no success info.

When I open  powershell 5.1.16299.637 which compact with windows 10, and execute the same New-EventLog command, I got the error message as following:
PS C:\WINDOWS\system32> New-EventLog -Source "SupperSocketService" -LogName "TestLog" -MessageResourceFile "C:\Test\TestApp.dll"
New-EventLog : The "SupperSocketService" source is already registered on the "localhost" computer.
At line:1 char:1
+ New-EventLog -Source "SupperSocketService" -LogName "TestLog" -Messag ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-EventLog], InvalidOperationException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.NewEventLogCommand
BrucePay commented 5 years ago

Hi @chucklu If the cmdlet successfully creates a new log, then nothing is returned by design. This reflects the underlying EventlLog API which also doesn't return anything on success. It looks like you ran the command on 6 and it succeeded with no output as expected. When you ran the command again on 5.1 it got an error because the log already existed. If you run the command on 6 again, you should now see the same error as you do on 5.1. Can you confirm that this is the case?

chucklu commented 5 years ago

@BrucePay Sorry, I misunderstood the source and the logname.