none
C# ASP.NET - Exchange PowerShell - Access Denied only on one command RRS feed

  • Question

  • I've created an ASP.NET web app that will mail enable a user. This works great and I have no problems with this. I recently added an option to hide and unhide a user from the global address list. This also works great on my development machine, but as soon as I put it on the server i get the error message "System.Management.Automation.Remoting.PSRemotingTransportException: Processing data from remote server failed with the following error message: Access is denied. For more information, see the about_Remote_Troubleshooting Help topic."

    I then try my mail enable code on the server and that works fine. I've tried running it as the enterprise administrator account and that makes no difference so I don't think it's an actual permission issue. Here is the code I am using.

    		    ICollection<PSObject> results;
                        SecureString password2 = new SecureString();
                        string username2 = userName + "@" + ConfigurationManager.AppSettings["FQDN"];
                        string str_password = passWord;
                        string liveIdconnectionUri = ConfigurationManager.AppSettings["liveIdconnectionUri"] + "?serializationLevel=Full";
                        foreach (char x in str_password)
                        {
                            password2.AppendChar(x);
                        }
    
                        PSCredential credential = new PSCredential(username2, password2);
                        WSManConnectionInfo connectionInfo = new WSManConnectionInfo((new Uri(liveIdconnectionUri)),
                            "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
    
                        connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;
                        connectionInfo.OpenTimeout = 1 * 60 * 1000;
                        connectionInfo.OperationTimeout = 1 * 60 * 1000;
    
                        Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
                        PowerShell powershell = PowerShell.Create();
                        PSCommand command = new PSCommand();
    
                        command.AddCommand("Set-Mailbox");
                        command.AddParameter("Identity", Session["Logon"].ToString() + "@" + ConfigurationManager.AppSettings["FQDN"]);
                        command.AddParameter("HiddenFromAddressListsEnabled", false);
                        //command.AddParameter("ErrorAction", "SilentlyContinue");
                        command.AddParameter("DomainController", ConfigurationManager.AppSettings["Exchange2010DomainControllerFQDN"]);
                        runspace.Open();
                        powershell.Runspace = runspace;
                        powershell.Commands = command;
                        results = powershell.Invoke();
                        if (powershell.Streams.Error != null && powershell.Streams.Error.Count > 0)
                        {
                            foreach (object item in powershell.Streams.Error.ReadAll())
                            {
    
                                this.MessageToUser.Style.Value = "";
                                this.LabelError.Text += "Mailbox Error: " + item.ToString();
                            }
                        }
                        if (results != null && results.Count > 0)
                        {
                            
    
                        }
                        runspace.Dispose();
                        runspace = null;
                        powershell.Dispose();
                        powershell = null;
    
    

    Monday, January 16, 2012 12:48 PM

Answers

  • I found out what it was! I was running this command in a large routine that was inside an impersonation code. Once i took it out of the impersonation code it worked!
    • Marked as answer by s10xtremenlow Monday, January 16, 2012 1:23 PM
    Monday, January 16, 2012 1:22 PM

All replies

  • I found out what it was! I was running this command in a large routine that was inside an impersonation code. Once i took it out of the impersonation code it worked!
    • Marked as answer by s10xtremenlow Monday, January 16, 2012 1:23 PM
    Monday, January 16, 2012 1:22 PM
  • Hi,

    Could you open your solution a bit? I though because I have "<identity impersonate="true"/>" in my web.config, the whole application is behaving as impersonated. I have very same issue than you, but in my case I faced this with Lync management.


    Petri

    Thursday, March 8, 2012 10:34 PM