C# Powershell - Exchange management {"Value cannot be null.\r\nParameter name: serverSettings"} -


i want interact microsoft.exchange.management.powershell.e2010 installed on machine through c# project.

my local machine windows server 2012 r2 standard , exchange server 2010 sp3 rollup update 14 installed.

i'm using 4.5 .net framework (downgrading older version isn't possible)

        wsmanconnectioninfo connectioninfo = new wsmanconnectioninfo();          connectioninfo.operationtimeout = 4 * 60 * 1000; // 4 minutes.         connectioninfo.opentimeout = 1 * 60 * 1000; // 1 minute.          runspace runspace = runspacefactory.createrunspace(connectioninfo);         runspace.open();         using (powershell ps = powershell.create())         {             ps.runspace = runspace;              ps.addcommand("add-pssnapin");             ps.addargument("microsoft.exchange.management.powershell.e2010");              var results = ps.invoke();              try             {                 ps.addcommand("get-mailbox");                  results = ps.invoke();             }             catch (exception e)             {              }         }         runspace.close(); 
  • i open remote shell session (targetted on local machine).
  • add exchange management pssnapin, in order have access exchange commands.
  • finally execute exchange management command.

\!/ problem @ last step, results = ps.invoke(); throws system.management.automation.remoteexception message "value cannot null.\r\nparameter name: serversettings".

do guys have idea?

thank time.

i've been fighting last couple days. know question few months old, thought i'd share solution found. in .config, need uselegacyv2runtimeactivationpolicy attribute set true on startup tag. so:

<startup uselegacyv2runtimeactivationpolicy="true">   <supportedruntime version="v4.0" sku=".netframework,version=v4.6.2"/> </startup> 

using this, able run get-mailbox command while targeting .net 4.6.2.


Comments