"WSMan Initialization failed with error code: -2144108171" error RRS feed

  • Question

  • I have MVC web app controller to connect exchange server powershell with the following codes:

    connectionInfo = new WSManConnectionInfo(new Uri(ConfigurationManager.AppSettings.Get("WSManConnectionInfo").ToString()), "", newCred);
                connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
    string rspace = "space is OK";
                    //--create remote runspace
                    runspace = RunspaceFactory.CreateRunspace(connectionInfo);
                } catch (Exception ex2)
                    rspace = ex2.Message.ToString();
                ViewBag.rspace = rspace; //show the above error message on client side view

    The above codes works fine from my local machine, but I got the above error after publishing to production server, please note I can see the "Microsoft.Management.Infrustructure.dll" is existed on the bin folder of production server.

    Edit: I even tried to add these 3 lines codes, but same error;

    connectionInfo.SkipCACheck = true;

    connectionInfo.SkipCNCheck = true;

    connectionInfo.MaximumConnectionRedirectionCount = 4;

    Edit: the System.Management.Automation.dll is also added in the Reference folder

    please let me know how to fix this error, thanks

    • Edited by Peter Cong Friday, February 14, 2020 2:58 PM
    Friday, February 14, 2020 2:58 PM

All replies

  • Sorry but this is a scripting forum.  You will have to ask questions about IIS code in teh IIS developers forums:


    Friday, February 14, 2020 3:10 PM
  • Sorry, I am not sure why I should go to IIS developers forum?

    My question basically is using C# script codes to access Exchange server through Powershell, it is powershell related question.

    I would appreciate if any expert can provide any solutions, thanks a lot, 

    Friday, February 14, 2020 3:25 PM
  • Because your issue has nothing to do with scripting.  It is C# MVC code that runs only on IIS.

    You posted: "I have MVC web app controller to connect exchange server PowerShell with the following codes:"

    Web Apps are supported by the IIS forum and not by scripting forums and not on MSDN.  The IIS forum is a Microsoft forum set up specifically for web development.


    Friday, February 14, 2020 3:31 PM
  • actually, I have posted it on, and they asked me to post it here since it is powershell related issue
    Friday, February 14, 2020 3:35 PM
  • Yes but the issue is how to use WsMan from a web server.  The IIS people will help you to find out how difficult that is to set up.  Also you are adding Exchange access which is even trickier.   Add to that that you are running compiled code and NIT PowerShell scripts.  This forum is for scripts and not for development or web server configuration issues. 

    Nearly all of the people in this forum are system admins or those learning basic scripting.  They will not be of much help.  Few here even know about the PowerShell SDK or anything about network security requirements and how a web server is restricted form network access by default and has to be correctly configured.  Also the target systems have to allow access from a service impersonating a user.

    The first thing any developer knows to do is to look up the error code and address the issue.  You haven't done that.  I suspect you are not a developer but are someone with an idea that may not be possible on teh web server you are working form.

    Assuming all things are set correctly then the error tells you where to look next:

    In coding "HRESULT" is the holy grail.  It tells us everything; to that end a web site can decode most results.  You can also use the internal message facility to ask Windows to give you the message for the code.  Windows development 101.

    To get teh message in C# use the following P/Invoke code:


    Friday, February 14, 2020 3:49 PM
  • sorry, the first two links from www.hresult are blocked by my company's entranet, I can not open it.
    Friday, February 14, 2020 4:03 PM
  • Too bad.  Can't help you if you are not able to use the Internet.

    Use you search engine or the code in the last link to decode your hresult.  This is something you have to learn how to do and use if you are going to be a developer.


    Friday, February 14, 2020 4:23 PM