Exchange server 仅在IIS承载的应用程序中远程连接到Exchange时引发异常
我希望有人能帮助我,我有以下功能可以远程调用powershell服务器:Exchange server 仅在IIS承载的应用程序中远程连接到Exchange时引发异常,exchange-server,remoting,credentials,Exchange Server,Remoting,Credentials,我希望有人能帮助我,我有以下功能可以远程调用powershell服务器: private static string DoCall() { string resultPs = string.Empty; string serverName = "myserver.com"; string SHELL_URI = "http://schemas.microsoft.com/powershell/Microsoft.Ex
private static string DoCall()
{
string resultPs = string.Empty;
string serverName = "myserver.com";
string SHELL_URI = "http://schemas.microsoft.com/powershell/Microsoft.Exchange";
System.Uri serverUri = new Uri(String.Format("http://{0}/powershell?serializationLevel=Full", serverName));
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(serverUri, SHELL_URI, (PSCredential)null);
//connectionInfo = new WSManConnectionInfo(serverUri, SHELL_URI, PSCredential.Empty);
//connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
try
{
using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
{
PowerShell powershell = PowerShell.Create();
powershell.Runspace = runspace;
runspace.Open();
powershell.AddScript("Get-DatabaseAvailabilityGroup");
Collection<PSObject> results = powershell.Invoke();
if (powershell.Streams.Error.Count > 0)
{
foreach (ErrorRecord err in powershell.Streams.Error)
{
resultPs += (err.ErrorDetails.Message != null ? err.ErrorDetails.Message : "");
}
}
foreach (PSObject result in results)
{
foreach (PSPropertyInfo propertyInfo in result.Properties)
{
resultPs += "Property:" + propertyInfo.Name + " Value:" + propertyInfo.Value;
}
}
powershell.Runspace.Close();
}
}
catch (Exception ex)
{
resultPs = ex.Message + " " + ex.StackTrace + " innerException: " + (ex.InnerException != null ? (ex.InnerException.Message ?? "") : "");
}
return resultPs;
}
}
我查看了几篇关于传递凭证的博客,但我没有发现有人有同样的问题,这解决了我的问题。我知道我可以使用重载方法初始化凭据,但我想使用应用程序池中的方法
"An internal error occurred. \0 at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.Initialize(Uri connectionUri, WSManConnectionInfo connectionInfo)\r\n at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager..ctor(Guid runspacePoolInstanceId, WSManConnectionInfo connectionInfo, PSRemotingCryptoHelper cryptoHelper)\r\n at System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerImpl..ctor(ClientRemoteSession session, PSRemotingCryptoHelper cryptoHelper, RunspaceConnectionInfo connectionInfo, URIDirectionReported uriRedirectionHandler)\r\n at System.Management.Automation.Remoting.ClientRemoteSessionImpl..ctor(RemoteRunspacePoolInternal rsPool, URIDirectionReported uriRedirectionHandler)\r\n at System.Management.Automation.Internal.ClientRunspacePoolDataStructureHandler..ctor(RemoteRunspacePoolInternal clientRunspacePool, TypeTable typeTable)\r\n at System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal..ctor(Int32 minRunspaces, Int32 maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo)\r\n at System.Management.Automation.Runspaces.RunspacePool..ctor(Int32 minRunspaces, Int32 maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo)\r\n at System.Management.Automation.RemoteRunspace..ctor(TypeTable typeTable, RunspaceConnectionInfo connectionInfo, PSHost host, PSPrimitiveDictionary applicationArguments)\r\n at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments)\r\n at TestingRemote.Service.DoCall() in "