我不明白我得到的NewNotImplementedException运行时错误

cas*_*rin 7 c# powershell exchange-server runspace

我正在尝试实现一个远程运行空间,它需要connectionInfo与Exchange通信,导入模块需要与活动目录通信.这是问题代码:

runspace = System.Management.Automation.Runspaces.RunspaceFactory.
CreateRunspace(psConnectionInfo);
runspace.InitialSessionState.ImportPSModule(new[] { "ActiveDirectory" });
runspace.Open();
Run Code Online (Sandbox Code Playgroud)

我得到的运行时错误是:

无法执行操作,因为操作"文件中的偏移32处的NewNotImplementedException:line:column:0:0"未实现

如果我省略该runspaceInitialSessionState行,则不会收到错误但是SetADServerSettingsViewEntireForest 的PowerShell命令无法运行,因为它无法识别.

堆栈跟踪:

无法执行操作,因为未实现操作"文件中的偏移32处的NewNotImplementedException:line:column:0:0".在System.Management.Automation.RemoteRunspace.get_InitialSessionState()位于c:\ Users\rtanner.CATNET\Documents\Visual Studio 2013\Projects\ManageUserForwardsWS\ManageUserForwardsWS\ManageUserForwards.asmx中的ManageUserForwardsWS.ManageUserForwards.SetExchangeCredentials(String userName,String PwString) .cs:第122行

我也可以使用此代码生成相同的错误:

        Pipeline pipeline = runspace.CreatePipeline();

        PowerShell powershell = PowerShell.Create();
        powershell.Runspace = pipeline.Runspace;

        powershell.Runspace.InitialSessionState.ImportPSModule(new[] { "ActiveDirectory" });
Run Code Online (Sandbox Code Playgroud)

这是StackTrace:

无法执行操作,因为未实现操作"文件中的偏移32处的NewNotImplementedException:line:column:0:0".在System.Management.Automation.RemoteRunspace.get_InitialSessionState()位于c:\ Users\rtanner.CATNET\Documents\Visual Studio 2013\Projects\ManageUserForwardsWS\ManageUserForwardsWS\ManageUserForwards.asmx中的ManageUserForwardsWS.ManageUserForwards.SetForward(String sAMAccountName,String fowardAddress) .cs:第151行

这个附加信息有帮助吗?有想法该怎么解决这个吗?

JPB*_*anc 1

据我在Microsoft 文档 Set-AdServerSettings中读到的内容不是ActiveDirectory模块的一部分,而是一个 Exchange CmdLet。

将 Exchange 命令行管理程序命令与托管代码结合使用Set-AdServerSettings一文显示了在 C# 中使用 CmdLet 时必须编写的代码。