7

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?

Erik Philips
  • 48,663
  • 7
  • 112
  • 142
caspersgrin
  • 231
  • 1
  • 5
  • 15
  • 1
    Do you mind adding the stack trace for that error? It may give some insight. – OnoSendai Jan 07 '14 at 18:50
  • Line 122 (see stack trace) is the `ImportPSModule()` line. – caspersgrin Jan 07 '14 at 19:21
  • Welcome to SO, Rob. +1 to your question, for showing good effort. Your previous comment though, should really be edited in to the question, since it might help others to help you and you don't want it to be hidden down in the comments. – Christoffer Lette Jan 07 '14 at 19:26
  • It may be an error on your ActiveDirectory module, or an auto-generated method that automatically implemented the NotImplementedException. Check this thread out: http://stackoverflow.com/questions/13929292/importpsmodule-failure-detection – OnoSendai Jan 07 '14 at 19:41
  • Yes, I think you are right and I'm going to have my Windows Administrator check it for me. From within a MD shell, I typed powershell to get into a powershell command shell. in the shell, I types the command: `import-module ActiveDirectory` and that worked fine and then `Set-AdServerSettings -ViewEntireForest $True`. the response that came back was basically that it didn't recognize it as the name of a cmdlet, script, or executable program. And that is wrong since that cmdlet is in the ActiveDirectory module. – caspersgrin Jan 08 '14 at 01:07

2 Answers2

1

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#.

JPBlanc
  • 63,198
  • 12
  • 118
  • 155
  • It may be in both but I've used it before in `ActiveDirectory`. The problem however, is that the failure is in importing the module. The code fails before it ever gets to the `Set-AdServerSettings` cmdlet. There is another way I can generate an error on PSImport, but it's a different error and I've updated my original post to include it. – caspersgrin Jan 08 '14 at 18:49
0

Remote Runspace constructor doesn't initialize and use InitialSessionState object. It works only with Local runspaces.

SAIL
  • 1
  • 1