0

I am trying to run a PowerShell command from within C#.

This is the code

PSCredential Credential = new PSCredential("domain.inet\adminuser", domainAdminPswrd);
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(
    new Uri("http://exchangeserver/powershell?serializationLevel=Full"),
    "http://schemas.microsoft.com/powershell/Microsoft.Exchange", Credential);

connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
PowerShell powershell = PowerShell.Create();

When I run the above code, the compiler halts at 'Runspace runspace' (second to last line) with the following error:

An unhandled exception of type 'System.InvalidProgramException' occurred

Additional information: Common Language Runtime detected an invalid program.

I have been trying to troubleshoot, but have had no luck so far.

3
  • Which .NET framework are you on? Commented Aug 12, 2014 at 5:32
  • I'm on .net 4.5 and VS Premium 2013 Commented Aug 12, 2014 at 20:13
  • I resolved this issue by installing KB2819745 on the machine running the c# program. (not the server I am connecting to) Commented Aug 12, 2014 at 21:55

1 Answer 1

3

I resolved this issue by installing KB2819745 on the machine running the c# program. (not the server I am connecting to)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.