none
Open runspace threw an exception of type System.Management.Automation.PSNotImplementedException RRS feed

  • Question

  • Hi,

    i am working on to create email box using SharePoint Web Part. Getting error when try to open runspace. 

    Code:

    // Set credentials to make a remote connection to Outlook Live 
                string userName = "sp.fam@mydomain.com";
                string password = "Pa$$word";
                int count = 0;
                SecureString secureString = new SecureString();
                foreach (char c in password) secureString.AppendChar(c);
                secureString.MakeReadOnly();
                PSCredential credentials = new PSCredential(userName, secureString);
                // Set the connection Info 

                WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("http://myexchange.mydomain.com/PowerShell"),
            "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credentials);
                connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;

                Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
                using (PowerShell powershell = PowerShell.Create())
                {
                    powershell.AddCommand("Get-Users");
                    powershell.AddParameter("ResultSize", count);

                    runspace.Open();
                    powershell.Runspace = runspace;
                    powershell.Invoke();
                }

    Error:
    base {System.NotImplementedException} = {"Cannot perform operation because operation \"NewNotImplementedException at offset 63 in file:line:column <filename unknown>:0:0\r\n\" is not implemented."}

    pls guide.

    thx


    iffi

    Monday, October 3, 2016 7:53 AM

All replies

  • Hi,

    Please replace these lines:

    using (PowerShell powershell = PowerShell.Create())
    {
         powershell.AddCommand("Get-Users");
         powershell.AddParameter("ResultSize", count); 
         runspace.Open(); 
         powershell.Runspace = runspace;
         powershell.Invoke();            
    }

    with these

    using (PowerShell powershell = PowerShell.Create())        
    {
     
        Command psCommand = new Command("Get-Users");
        psCommand.Parameters.Add("ResultSize", count);
        powershell.Commands.AddCommand(psCommand);
        runspace.Open();
        powershell.Runspace = runspace;
        powershell.Invoke();            
    }

    Also try to use BASIC auth like this

    AuthenticationMechanism.Basic;

    Regards,


    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com

    Sunday, October 9, 2016 3:02 PM
  • Hi,

    let me check and get back to you.

    thanks


    iffi

    Monday, October 10, 2016 6:51 AM
  • Hi,
    I tried but still getting error. i tried basic authentication, use IP instead of server name but still getting error. pls guide how to fix it thanks.


    Server Error in '/' Application.
    --------------------------------------------------------------------------------

    Connecting to remote server http://exchangeserver failed with the following error message : Access is denied. 
    For more information, see the about_Remote_Troubleshooting Help topic. 

    Thx

    iffi

    Friday, October 21, 2016 6:02 AM
  • Hi,

    Please mention the error here.

    Also, you might know, that you have to prepare your target Exchange server for Remote PowerShell. For that you can follow steps from here, if you have not already done:

    http://portal.hostingcontroller.com/kb/a223/how-to-enable-remote-power-shell-for-hc-in-exchange-2013-2016.aspx

    If you are using BASIC auth, you must pass HTTPS url like this:

    https://myexchange.mydomain.com/PowerShell

    Regards,


    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com

    Saturday, October 22, 2016 2:53 PM