간단한 웹 인터페이스를 통해 Exchange에서 다른 사용자의 부재 중 메시지를 업데이트 할 수있는 앱이 있습니다.RunSpace를 만들 때 내부 오류가 발생했습니다.
이 서비스를 Exchange로 연결 Microsoft.Exchange.WebServices
를 사용하여 사용하지만, 내가 EWS
를 통해 OOF 메시지를 업데이트하는 계정이 필요합니다 ((이 일을했다하더라도)에 의한 시스템 계정에 필요한 사용 권한이를 포기했다 생성에서 내 초기 시도 FULL 사서함 사용 권한). 내 컴퓨터 또는 서버에 EXE로 로컬로 실행할 때이 또한 작동
public class ExchangeShell
{
private Runspace MyRunSpace;
private PowerShell MyPowerShell;
private Uri ExchangeServer;
public ExchangeShell()
{
var exchangeserverurl = new Uri("http://EXCHANGESERVER/PowerShell");
var psCredential = GetCredentials();
var connectionInfo = new WSManConnectionInfo(exchangeserverurl, "http://schemas.microsoft.com/powershell/Microsoft.Exchange", psCredential);
try
{
MyRunSpace = RunspaceFactory.CreateRunspace(connectionInfo);
}
catch (Exception ex)
{
Email.Send($"Unable to connect \n\n Error: {ex.Message} ");
Environment.Exit(Environment.ExitCode);
}
}
public OofSettings GetOofSettings(string email)
{
using (MyRunSpace)
{
MyRunSpace.Open();
using (var powerShell = PowerShell.Create())
{
powerShell.Runspace = MyRunSpace;
var command = new PSCommand();
command.AddCommand("Get-MailboxAutoReplyConfiguration");
command.AddParameter("Identity", email);
powerShell.Commands = command;
var result = powerShell.Invoke();
var oofSetting = new OofSettings();
oofSetting.State = (OofState)Enum.Parse(typeof(OofState), result[0].Properties["AutoReplyState"].Value.ToString());
oofSetting.Duration = new TimeWindow((DateTime)result[0].Properties["StartTime"].Value, (DateTime)result[0].Properties["EndTime"].Value);
oofSetting.ExternalAudience = (OofExternalAudience)Enum.Parse(typeof(OofExternalAudience), result[0].Properties["ExternalAudience"].Value.ToString());
oofSetting.InternalReply = result[0].Properties["InternalMessage"].Value.ToString();
oofSetting.ExternalReply = result[0].Properties["ExternalMessage"].Value.ToString();
return oofSetting;
}
}
}
private PSCredential GetCredentials()
{
var secureString = new SecureString();
foreach (char c in @"PASSWORD")
{
secureString.AppendChar(c);
}
return new PSCredential("SERVICEACCOUNT", secureString);
}
}
:
그래서이 문제를 극복하기 위해, 나는 같은 일을 달성하기 위해PowerShell
원격을 사용하여 다음과 같은 클래스를 만들었습니다.
그러나, 나는 이것이 내가이 라인에 오류를보고하고 IIS를 통해 호스트 경우는 :
MyRunSpace = RunspaceFactory.CreateRunspace(connectionInfo);
내부 오류가 발생했습니다.
이것은 매우 유용한 오류 메시지는 아니며이 문제를 어떻게 해결할 수 있는지 잘 모르겠습니다. 누구든지 이것에 대한 제안이 있습니까? '
Category Message From First(s) From Last(s)
aspx.page Begin PreInit
aspx.page End PreInit 0.000025 0.000025
aspx.page Begin Init 0.000035 0.000009
aspx.page End Init 0.000057 0.000022
aspx.page Begin InitComplete 0.000065 0.000008
aspx.page End InitComplete 0.000073 0.000008
aspx.page Begin PreLoad 0.000081 0.000008
aspx.page End PreLoad 0.000093 0.000012
aspx.page Begin Load 0.000101 0.000008
하지만 난 정말 돈 :
업데이트
나는 web.config
에 추적기를 부착하고 여기에 사무실 세부 사항들이 밖으로을 검색하는 사용자를 선택한 후 일부 추적 정보입니다 이 정보를 무엇으로 만들지는 알지 못합니다. 실제로 runspace
과 서버간에 실제로 진행되고있는 것에 대해서는 많이 밝혀지지 않은 것 같습니다.
스택 추적 : System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.Initialize System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager에서 (URI는 ConnectionUri, WSManConnectionInfo에서 ConnectionInfo) 에서
.. System.Man에서 System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerImpl..ctor에서의 ctor (GUID runspacePoolInstanceId, WSManConnectionInfo에서 ConnectionInfo, PSRemotingCryptoHelper cryptoHelper) (ClientRemoteSession 세션 PSRemotingCryptoHelper cryptoHelper, RunspaceConnectionInfo에서 ConnectionInfo, URIDirectionReported uriRedirectionHandler) agement.Automation.Remoting.ClientRemoteSessionImpl..ctor System.Management.Automation.Runspaces.Internal에서 System.Management.Automation.Internal.ClientRunspacePoolDataStructureHandler..ctor에서 (RemoteRunspacePoolInternal rsPool, URIDirectionReported uriRedirectionHandler) (RemoteRunspacePoolInternal clientRunspacePool, TypeTable typeTable) . RemoteRunspacePoolInternal..ctor (minRunspaces INT32, INT32 maxRunspaces, TypeTable typeTable, PSHost 호스트 PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo에서 ConnectionInfo) System.Management.Automation.Runspaces.RunspacePool..ctor (minRunspaces INT32, INT32 maxRunspaces에서 , TypeTable typeTable, PSHost 호스트 PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo) at System.Management.SetOutOfOffice.ExchangeShell에서 System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace (RunspaceConnectionInfo에서 ConnectionInfo, PSHost 호스트 TypeTable typeTable, PSPrimitiveDictionary applicationArguments) 에서 Automation.RemoteRunspace..ctor (TypeTable typeTable, RunspaceConnectionInfo에서 ConnectionInfo, PSHost 호스트 PSPrimitiveDictionary applicationArguments) ..ctor()
답변 주셔서 감사합니다. 글렌, 나는 그'connectionInfo' 검사를 건너 뛰려고했지만 성공하지 못했습니다. 'trace.axd'를 확인한 후에 나는 유용한 정보를 볼 수 없다. (아마 내가 그것을 올바르게 읽지는 못했을지라도) - 나는 나의 질문에 몇 가지를 올렸다. – Bassie