title: Access denied when using powershell on IIS webserver
body: <p>I have a password reset website for my 0ffice 365 users.  It runs powershell commands in the background to reset user passwords.  For some reason when I am using VS and I run the browser with the page it works fine.  However when I run it from the live site I get this error</p>
  
  <pre><code>Processing data from remote server failed with the following error message: Access is denied. For more information, see the about_Remote_Troubleshooting Help topic. 
  </code></pre>
  
  <p>The page is aspx.net with C# code behind.</p>
  
  <p>I have tried using the impersonator class but that does not work either.</p>
  
  <p>Here is some of my code.</p>
  
  <pre><code> using (new Impersonator("user", "domain", "pass"))
      {
  
          PSCredential creds = new PSCredential("office365email", "password");
  
          WSManConnectionInfo connectionInfo = new WSManConnectionInfo(
              new Uri("https://server.outlook.com/PowerShell-LiveID?PSVersion=2.0"),
              "http://schemas.microsoft.com/powershell/Microsoft.Exchange", creds);
          connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
  
  
  
          Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
  
          runspace.ApartmentState = System.Threading.ApartmentState.STA;
          runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;
  
          try
          {
  
  
              runspace.Open();
  
  
              pipeline = runspace.CreatePipeline();
  
              Command forwardcommand = new Command("Set-Mailbox");
              forwardcommand.Parameters.Add("Identity", user);
              forwardcommand.Parameters.Add("Password", pass);
  
  
  
  
              pipeline.Commands.Add(forwardcommand);
  
              try
              {
                  pipeline.Invoke();
  
  
  
                  runspace.Close();
                  pipeline.Stop();
                  return "Password Successfully Changed";
  
  
  
              }
              catch (Exception er)
              {
                  runspace.Close();
                  pipeline.Stop();
  
                  return er.Message;
  
  
              }
          }
          catch (PSRemotingTransportException eer)
          {
  
              runspace.Close();
  
  
              return eer.Message;// "Server busy please try again later";
          }
      }
  </code></pre>
  
  <p>Any ideas why I can't do it from the actual website but I can on my local host?</p>
  
  <pre><code>&lt;authentication mode="Windows"/&gt;
      &lt;roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"&gt;
          &lt;providers&gt;
              &lt;clear/&gt;
              &lt;add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/&gt;
              &lt;add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider"/&gt;
          &lt;/providers&gt;
      &lt;/roleManager&gt;
      &lt;identity impersonate="true"/&gt;
  </code></pre>