我运行下面的代码:的PowerShell /运行空间
RunspaceConfiguration config = RunspaceConfiguration.Create();
PSSnapInException warning;
config.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out warning);
if (warning != null) throw warning;
Runspace thisRunspace = RunspaceFactory.CreateRunspace(config);
thisRunspace.Open();
string alias = usr.AD.CN.Replace(' ', '.');
string letter = usr.AD.CN.Substring(0, 1);
string email = alias + "@" + (!usr.Mdph ? Constantes.AD_DOMAIN : Constantes.MDPH_DOMAIN) + "." + Constantes.AD_LANG;
string db = "CN=IS-" + letter + ",CN=SG-" + letter + ",CN=InformationStore,CN=" + ((char)letter.ToCharArray()[0] < 'K' ? Constantes.EXC_SRVC : Constantes.EXC_SRVD) + Constantes.EXC_DBMEL;
string cmd = "Enable-Mailbox -Identity \"" + usr.AD.CN + "\" -Alias " + alias + " -PrimarySmtpAddress " + email + " -DisplayName \"" + usr.AD.CN + "\" -Database \"" + db + "\"";
Pipeline thisPipeline = thisRunspace.CreatePipeline(cmd);
thisPipeline.Invoke();
的代码是在一个线程中运行的创建方式:
t.WorkThread = new Thread(cu.CreerUser);
t.WorkThread.Start();
如果我直接运行的代码(不通过一个线程),它的工作。
在线程中抛出以下异常:ObjectDisposedException“安全句柄已关闭。” (译自法语)
然后,我替换了“Open”wirh“OpenAsync”,它帮助没有得到以前的异常。 但是,当调用时,我得到以下异常:InvalidRunspaceStateException“无法调用管道,因为其执行状态未打开,其当前状态为打开。” (同样来自法国的翻译)
我无言以对......
任何帮助,欢迎! 谢谢!
随着开放:
à Microsoft.Win32.Win32Native.GetTokenInformation(SafeTokenHandle TokenHandle, UInt32 TokenInformationClass, SafeLocalAllocHandle TokenInformation, UInt32 TokenInformationLength, UInt32& ReturnLength)
à System.Security.Principal.WindowsIdentity.GetTokenInformation(SafeTokenHandle tokenHandle, TokenInformationClass tokenInformationClass, UInt32& dwLength)
à System.Security.Principal.WindowsIdentity.get_User()
à System.Security.Principal.WindowsIdentity.GetName()
à System.Security.Principal.WindowsIdentity.get_Name()
à System.Management.Automation.MshLog.GetLogContext(ExecutionContext executionContext, InvocationInfo invocationInfo, Severity severity)
à System.Management.Automation.MshLog.GetLogContext(ExecutionContext executionContext, InvocationInfo invocationInfo)
à System.Management.Automation.MshLog.LogEngineLifecycleEvent(ExecutionContext executionContext, EngineState engineState, InvocationInfo invocationInfo)
à System.Management.Automation.MshLog.LogEngineLifecycleEvent(ExecutionContext executionContext, EngineState engineState)
à System.Management.Automation.Runspaces.LocalRunspace.OpenHelper()
à System.Management.Automation.Runspaces.RunspaceBase.CoreOpen(Boolean syncCall)
à System.Management.Automation.Runspaces.RunspaceBase.Open()
à Cg62.ComposantsCommuns.ActiveDirectory.Exchange.BoitesAuxLettres.CreationBAL(User usr, IList`1 log) dans D:\Applications\Commun\Sources .Net\COMIAD\COMIAD\Exchange.cs:ligne 141
à Cg62.ComposantsCommuns.ActiveDirectory.ComptesUtilisateurs.CreationUser.CreerUser() dans D:\Applications\Commun\Sources .Net\COMIAD\COMIAD\ComptesUtilisateurs.cs:ligne 199
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.runTryCode(Object userData)
à System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
随着OpenAsync:
à System.Management.Automation.Runspaces.RunspaceBase.AddToRunningPipelineList(PipelineBase pipeline)
à System.Management.Automation.Runspaces.RunspaceBase.DoConcurrentCheckAndAddToRunningPipelines(PipelineBase pipeline, Boolean syncCall)
à System.Management.Automation.Runspaces.PipelineBase.CoreInvoke(IEnumerable input, Boolean syncCall)
à System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
à System.Management.Automation.Runspaces.Pipeline.Invoke()
à Cg62.ComposantsCommuns.ActiveDirectory.Exchange.BoitesAuxLettres.CreationBAL(User usr, IList`1 log) dans D:\Applications\Commun\Sources .Net\COMIAD\COMIAD\Exchange.cs:ligne 149
à Cg62.ComposantsCommuns.ActiveDirectory.ComptesUtilisateurs.CreationUser.CreerUser() dans D:\Applications\Commun\Sources .Net\COMIAD\COMIAD\ComptesUtilisateurs.cs:ligne 199
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.runTryCode(Object userData)
à System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
很抱歉这么晚才回复...我怎么回事
升级到了很多Powershell 2.0和我通过了打开错误 但现在我在Invoke上有以下内容。 我将我的命令更改为:
Enable-Mailbox -Identity "Aagtest Abe" -Alias Aagtest.Abe -PrimarySmtpAddress [email protected] -DisplayName "Aagtest Abe" -Database "myDb" -DomainController adc.domain.int
该命令在PowerShell中正常工作。 我收到以下异常CmdletInvocationException: “没有例外,只能使用'<模块>'。” 如何把这种......不知道
堆栈跟踪:
à Microsoft.Exchange.Data.Directory.DSAccessTopologyProvider..ctor(String machineName)
à Microsoft.Exchange.Data.Directory.DSAccessTopologyProvider..ctor()
à Microsoft.Exchange.Data.Directory.DirectoryServicesTopologyProvider.DiscoverConfigDC()
à Microsoft.Exchange.Data.Directory.DirectoryServicesTopologyProvider..ctor()
à Microsoft.Exchange.Data.Directory.TopologyProvider.InitializeInstance()
à Microsoft.Exchange.Data.Directory.TopologyProvider.GetInstance()
à Microsoft.Exchange.Data.Directory.ADSession.GetConnection(String preferredServer, Boolean isWriteOperation, Boolean isNotifyOperation, ADObjectId& rootId)
à Microsoft.Exchange.Data.Directory.ADSession.GetReadConnection(String preferredServer, ADObjectId& rootId)
à Microsoft.Exchange.Data.Directory.ADSession.IsReadConnectionAvailable()
à Microsoft.Exchange.Configuration.Tasks.RecipientObjectActionTask`2.InternalBeginProcessing()
à Microsoft.Exchange.Management.RecipientTasks.EnableMailbox.InternalBeginProcessing()
à Microsoft.Exchange.Configuration.Tasks.Task.BeginProcessing()
à System.Management.Automation.Cmdlet.DoBeginProcessing()
à System.Management.Automation.CommandProcessorBase.DoBegin()
我遇到同样的问题。你有没有收到答案?问题出现在两年内运行正常的代码中(在Windows Vista,Windows 7和Windows Server 2003上测试过)。但是自从我们在Windows Server 2008上部署以来,我们遇到了这个错误。 – 2009-09-24 14:24:56