question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The term 'new-eventlog' is not recognized as a name of a cmdlet

See original GitHub issue

Prerequisites

Steps to reproduce

execute: New-EventLog -LogName Application -Source "Blah Blah"

Expected behavior

whatever the previous output was in 5.X

Actual behavior

>new-eventlog: The term 'new-eventlog' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Error details

>
Exception             :
    Type        : System.Management.Automation.CommandNotFoundException
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : The term 'new-eventlog' is not recognized as a name of a cmdlet, function, script file, or
executable program.
                      Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
            HResult : -2146233087
        TargetObject          : new-eventlog
        CategoryInfo          : ObjectNotFound: (new-eventlog:String) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : CommandNotFoundException
        InvocationInfo        :
            ScriptLineNumber : 1
            OffsetInLine     : 1
            HistoryId        : 6
            Line             : new-eventlog -logname application -source "Blah Blah"
            PositionMessage  : At line:1 char:1
                               + new-eventlog -logname application -source "Blah Blah"
                               + ~~~~~~~~~~~~
            InvocationName   : new-eventlog
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    CommandName : new-eventlog
    TargetSite  :
        Name          : LookupCommandInfo
        DeclaringType : System.Management.Automation.CommandDiscovery, System.Management.Automation,
Version=7.2.6.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message     : The term 'new-eventlog' is not recognized as a name of a cmdlet, function, script file, or
executable program.
                  Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
    Data        : System.Collections.ListDictionaryInternal
    Source      : System.Management.Automation
    HResult     : -2146233087
    StackTrace  :
   at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandTypes commandTypes,
SearchResolutionOptions searchResolutionOptions, CommandOrigin commandOrigin, ExecutionContext context)
   at System.Management.Automation.CommandDiscovery.TryModuleAutoDiscovery(String commandName, ExecutionContext
context, String originalCommandName, CommandOrigin commandOrigin, SearchResolutionOptions searchResolutionOptions,
CommandTypes commandTypes, Exception& lastError)
   at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandTypes commandTypes,
SearchResolutionOptions searchResolutionOptions, CommandOrigin commandOrigin, ExecutionContext context)
   at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)
   at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[]
commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput,
CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][]
commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject          : new-eventlog
CategoryInfo          : ObjectNotFound: (new-eventlog:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
InvocationInfo        :
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 6
    Line             : new-eventlog -logname application -source "Blah Blah"
    PositionMessage  : At line:1 char:1
                       + new-eventlog -logname application -source "Blah Blah"
                       + ~~~~~~~~~~~~
    InvocationName   : new-eventlog
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

>Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

Shouldn’t that cmdlet work now in 7.x in Windows?

The RFC, Importing Windows PowerShell modules in PowerShell Core, is Final which means “fully complete and implemented in PowerShell”, right (source)?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mklement0commented, Oct 14, 2022

New-EventLog is indeed only available in Windows PowerShell.

See the conceptual about_Windows_PowerShell_Compatibility help topic.

For in-session use in PowerShell Core (with cross-process serialization behind the scenes), you can make New-EventLog available, as follows, but note the limitations discussed in the linked help topic:

Import-Module  Microsoft.PowerShell.Management -UseWindowsPowerShell -WarningAction Ignore

New-EventLog -?  # This should now print help information, implying that New-EventLog is now available.

Note:

  • -WarningAction Ignore suppresses two warnings:

    • The specific warning about which specific commands are not imported (via proxies), due to conflicting with edition-native versions of those commands.
    • The general warning about the limitations of providing the commands via cross-process serialization; note that this warning as of PowerShell Core 7.3.0-preview.8 contains misleading information:
      • It mentions -AllowClobber, which isn’t a supported parameter; the real parameter name, -NoClobber, has the inverse logic and is implied when you use -UseWindowsPowerShell
      • It mentions -SkipEditionCheck, which would not be effective in this case (leaving aside the fact that it is described as a necessary step, even though (parts of) the module already have been imported).
  • While 3>$null is usually equivalent to -WarningAction Ignore / -WarningAction SilentlyContinue , it fails to suppress the specific warning in this case.

1reaction
237dmitrycommented, Oct 13, 2022

In Windows PowerShell.

PS > powershell -c Get-Command -Module Microsoft.PowerShell.Management New-*
Read more comments on GitHub >

github_iconTop Results From Across the Web

Powershell New-EventLog Error
1 Answer 1 ... You do not have a version of PowerShell that has New-EventLog cmdlet. Run the following to get a list...
Read more >
New-EventLog (Microsoft.PowerShell.Management)
Specifies the name of the event log. If the log does not exist, New-EventLog creates the log and uses this value for the...
Read more >
Solved: Powershell writing entries to Windows Event logs
New-EventLog : The term 'New-EventLog' is not recognized as the name of a cmdlet, function, script file, or operable program.
Read more >
PowerShell Versions
The term 'Write-EventLog' is not recognized as the name of a cmdlet, function, script file, or operable program.
Read more >
New event log nowhere to be found after creating in ...
Through PowerShell, I am attempting to create a new event log and write a test entry to it, but it is not showing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found