2014-01-07 55 views
6

我想實現一個遠程運行空間,它需要connectionInfo與Exchange交談並且導入模塊與活動目錄交談。這是問題的代碼:我不明白我得到的NewNotImplementedException運行時錯誤

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

運行時的錯誤,我得到的是:

因爲操作無法執行操作「NewNotImplementedException在文件偏移32:行:列:0:0」未實現

如果我省略runspaceInitialSessionState行,我沒有收到錯誤,但ViewEntireForest的PowerShell命令SetADServerSettings無法運行,因爲它無法識別。

堆棧跟蹤:因爲操作 「NewNotImplementedException在文件偏移32:行:柱:0:0」

無法執行操作未實現。at System.Management.Automation.RemoteRunspace.get_InitialSessionState() at c:\ Users \ rtanner.CATNET \ Documents \ Visual Studio 2013 \ Projects \ ManageUserForwardsWS \ ManageUserForwardsWS \ ManageUserForwards中ManageUserForwardsWS.ManageUserForwards.SetExchangeCredentials(String userName,String PwString) .asmx.cs:行122

我還可以生成與此代碼,而不是相同的錯誤:

 Pipeline pipeline = runspace.CreatePipeline(); 

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

     powershell.Runspace.InitialSessionState.ImportPSModule(new[] { "ActiveDirectory" }); 

而這裏的堆棧跟蹤:

無法執行操作,因爲未執行「文件:行:列:0:0中的偏移量32處的NewNotImplementedException」操作。at System.Management.Automation.RemoteRunspace.get_InitialSessionState() at c:\ Users \ rtanner.CATNET \ Documents \ Visual Studio 2013 \ Projects \ ManageUserForwardsWS \ ManageUserForwardsWS \ ManageUserForwards中ManageUserForwardsWS.ManageUserForwards.SetForward(String sAMAccountName,String fowardAddress) .asmx.cs:line 151

這個補充信息有幫助嗎?有想法該怎麼解決這個嗎?

+1

您是否介意爲該錯誤添加堆棧跟蹤?它可能會提供一些見解。 – OnoSendai

+0

添加StackTrace! – caspersgrin

+0

第122行(見堆棧跟蹤)是'ImportPSModule()'行。 – caspersgrin

回答

1

據我所知Microsoft documentionSet-AdServerSettings不是ActiveDirectory模塊的一部分,但是是一個Exchange CmdLet。

Using Exchange Management Shell Commands With Managed Code文章顯示您必須編寫代碼才能使用Set-AdServerSettings CmdLet in C#。

+0

它可能在兩者中,但我已經在'ActiveDirectory'中使用它。但是,問題在於導入模塊失敗。代碼在到達Set-AdServerSettings cmdlet之前失敗。還有一種方法可以在PSImport上生成錯誤,但這是一個不同的錯誤,我更新了原始文章以包含它。 – caspersgrin