PSNotImplementedException when running PowerShell commands in C# RRS feed

  • Question

  • I am working on a software tool for performing automated deployment and various other admin tasks using PowerShell in a C# application. I keep running into this 'PSNotImplementedException' in my output, which seems to be killing worker threads in the RunspacePool without explanation. My current code is running a test copied directly from the PowerShell 3.0 sample from Microsoft posted here:

    I have also seen this exception thrown consistently in a previous test based upon Keith Babinec's excellent blog post here:

    The error suggests that there is some method(s) being called in the System.Management.Automation.dll which is not implemented, and not in my managed code, but I can't see any clear information about what the problem is.

    So my question is: what exactly is this trying to tell me, and how can I protect against this recurring problem? Am I missing some important step in the process?

    I'm no system administrator, and this is my first time working with PowerShell, so you'll forgive me if the explanation is a very simple one. I would think that the code directly from Microsoft would run without mysterious errors however.


    Wednesday, October 25, 2017 4:49 PM

All replies

  • Hello danatsquint ,

    I have run the demo you provided and it works well on my side.

    The running environment is .Net framework 4.5 and System.Management.Automation version is 3.0.

    And I have noticed versions 6.1.7601.* are unofficial packages for .Net 4.0 and are not supported by Microsoft, Please ensure you are not in this case.

    please provide entire error message and your running environment.


    Neil Hu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, October 27, 2017 11:11 AM
  • Hi Neil,

    I have refactored my code on several occasions since posting this question, but I am still not getting to the root of the problems I'm having with my approach and I'm still seeing unexplained, incomprehensible errors.

    My project is targeting .NET 4.5, and references System.Management.Automation version 3.0, located at: C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll

    I'm using VS 2017 on Windows 7 and I have PowerShell 5.0 installed. Should I consider downgrading to a lower version of Windows PowerShell? Which version is most appropriate?

    As for errors...

    As soon as I execute the following code:

    m_runspacePool = RunspaceFactory.CreateRunspacePool(1,5);

    ... I get this exception:

    System.EntryPointNotFoundException occurred
      Message=Unable to find an entry point named 'WTGetSignatureInfo' in DLL 'wintrust.dll'.
       at System.Management.Automation.Security.NativeMethods.WTGetSignatureInfo(String pszFile, IntPtr hFile, SIGNATURE_INFO_FLAGS sigInfoFlags, SIGNATURE_INFO& psiginfo, IntPtr& ppCertContext, IntPtr& phWVTStateData)
       at System.Management.Automation.SignatureHelper.GetSignatureFromCatalog(String filename)

    Which is followed by this error:

    System.DllNotFoundException occurred
      Message=Unable to load DLL 'amsi.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
       at System.Management.Automation.AmsiUtils.AmsiNativeMethods.AmsiInitialize(String appName, IntPtr& amsiContext)
       at System.Management.Automation.AmsiUtils.ScanContent(String content, String sourceMetadata)

    And this one:

    System.Security.SecurityException occurred
      Message=Security error.
       at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)

    And this one, several times (I'm guessing once for each available runspace):

    System.Management.Automation.PipelineStoppedException occurred
      Message=The pipeline has been stopped.
       at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)

    I am experiencing some other errors too but these ones are the newest.

    • Edited by danatsquint Monday, November 6, 2017 5:41 PM
    Monday, November 6, 2017 5:40 PM
  • the first error message shows that the you  have issues with the "wintrust.dll" that comes from operate system .You need to check the "wintrust.dll" it's broken or not. I bet you reference System.Management.Automation in a wrong ways, try to download System.Management.Automation dll form nuget tools.
    Sunday, November 12, 2017 2:59 PM