I am using Exchange server 2013. I am getting below Exception when try to run my C# code in IIS.
System.Management.Automation.Remoting.PSRemotingTransportException: Connecting to remote server exchangeserver.admin.com failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
But locally [in Visual studio] my code is working fine , after publish my code and running through IIS i am getting Exception.
Please see the code
var runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
object psSessionConnection;
// Create a powershell session for remote exchange server
using (var powershell = PowerShell.Create())
{
var command = new PSCommand();
command.AddCommand("New-PSSession");
command.AddParameter("ConfigurationName", "Microsoft.Exchange");
command.AddParameter("ConnectionUri", new Uri("http://ExchangeServer.admin.com/powershell/Microsoft.Exchange"));
// command.AddParameter("Authentication", "Kerberos");
powershell.Commands = command;
powershell.Runspace = runspace;
// TODO: Handle errors
var result = powershell.Invoke();
Collection<ErrorRecord> errors = powershell.Streams.Error.ReadAll();
if (errors != null || errors.Count > 0)
{
foreach (ErrorRecord er in errors)
{
//log.Error(er.Exception.ToString());
return er.Exception.ToString();
}
}
psSessionConnection = result[0];
}
IIS was unable to access Powershell session for remote Exchange server, why ?
Please share your Ideas