Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I don't understand the NewNotImplementedException runtime error I'm getting

I'm trying to implement a remote runspace that needs both connectionInfo to talk to Exchange and an imported module to talk to active directory. Here is problem code:

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

The runtime error I get is:

Cannot perform operation because operation "NewNotImplementedException at offset 32 in file:line:column :0:0" is not implemented

If I omit the runspaceInitialSessionState line I don't get the error but the PowerShell command SetADServerSettings to ViewEntireForest fails to run because it's not recognized.

StackTrace:

Cannot perform operation because operation "NewNotImplementedException at offset 32 in file:line:column :0:0 " is not implemented. at System.Management.Automation.RemoteRunspace.get_InitialSessionState() at ManageUserForwardsWS.ManageUserForwards.SetExchangeCredentials(String userName, String PwString) in c:\Users\rtanner.CATNET\Documents\Visual Studio 2013\Projects\ManageUserForwardsWS\ManageUserForwardsWS\ManageUserForwards.asmx.cs:line 122

I can also generate the same error with this code instead:

        Pipeline pipeline = runspace.CreatePipeline();

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

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

And here's the StackTrace:

Cannot perform operation because operation "NewNotImplementedException at offset 32 in file:line:column :0:0" is not implemented. 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

Does this added information help? Any ideas on how to fix this?

like image 487
caspersgrin Avatar asked Jan 07 '14 18:01

caspersgrin


1 Answers

As far as I can read in Microsoft documention Set-AdServerSettings is not part of ActiveDirectory module but is an Exchange CmdLet.

Using Exchange Management Shell Commands With Managed Code article show the code you have to write to use Set-AdServerSettings CmdLet in C#.

like image 166
JPBlanc Avatar answered Oct 07 '22 07:10

JPBlanc