我正在尝试实现一个远程运行空间,需要连接信息来与Exchange通信并导入模块以与活动目录进行通信。这是有问题的代码:
runspace = System.Management.Automation.Runspaces.RunspaceFactory.
CreateRunspace(psConnectionInfo);
runspace.InitialSessionState.ImportPSModule(new[] { "ActiveDirectory" });
runspace.Open();
我得到的运行时错误是:
``` 无法执行操作,因为操作“文件:行:列中偏移量为32的NewNotImplementedException”未实现 ```
如果我省略`runspaceInitialSessionState`行,则不会出现错误,但PowerShell命令`SetADServerSettings`无法运行,因为它无法被识别。
堆栈跟踪:
``` 无法执行操作,因为操作“文件:行:列中偏移量为32的NewNotImplementedException”未实现。 在System.Management.Automation.RemoteRunspace.get_InitialSessionState() 在ManageUserForwardsWS.ManageUserForwards.SetExchangeCredentials(String userName, String PwString) in c:\Users\rtanner.CATNET\Documents\Visual Studio 2013\Projects\ManageUserForwardsWS\ManageUserForwardsWS\ManageUserForwards.asmx.cs:line 122 ```
我也可以使用以下代码生成同样的错误。
Pipeline pipeline = runspace.CreatePipeline();
PowerShell powershell = PowerShell.Create();
powershell.Runspace = pipeline.Runspace;
powershell.Runspace.InitialSessionState.ImportPSModule(new[] { "ActiveDirectory" });
以下是StackTrace:
无法执行操作,因为操作“文件中偏移量为32的NewNotImplementedException : 行:0:0”未实现。 at System.Management.Automation.RemoteRunspace.get_InitialSessionState() at ManageUserForwardsWS.ManageUserForwards.SetForward(String sAMAccountName, String fowardAddress) in c:\Users\rtanner.CATNET\Documents\Visual Studio 2013\Projects\ManageUserForwardsWS\ManageUserForwardsWS\ManageUserForwards.asmx.cs:line 151
这些额外的信息有帮助吗?有什么修复的想法吗?
import-module ActiveDirectory
,它可以正常工作,然后输入Set-AdServerSettings -ViewEntireForest $True
。返回的响应基本上是未能识别它作为cmdlet、脚本或可执行程序的名称。这是错误的,因为该cmdlet在ActiveDirectory模块中。 - caspersgrin