我有一个以编程方式在Exchange Server上调用PowerShell命令的应用程序。将应用程序连接到Exchange在线服务器outlook.office365.com是成功的,并且调用单个命令可以工作,但是在短时间内按顺序发送多个命令,服务器会变得阻塞并回复下面的消息。
我尝试使用runspace.Close和runspace.Dispose,但它没有任何效果。
从下面的消息,我看到在60秒内最多有5个运行空间,但是我的代码我正在关闭并处理运行空间,并且该限制不应该是问题。当然,我总是有可能做错事。
消息(某些文字用点掩盖):
Connecting to remote server failed with the following error message : Fail to create runspace because you have exceeded your budget to create runspace. Please wait for 45 seconds.
Policy: CN=GlobalThrottlingPolicy_....,CN=Global Settings,CN=ExchangeLabs,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=namprd05,DC=prod,DC=outlook,DC=com;
Snapshot: Owner: Sid~NAMPR05A001\.......~WSMan~false
BudgetType: WSMan
ActiveRunspaces: 0/3
Balance: 600000/1800000/-3000000
PowerShellCmdletsLeft: 199/200
ExchangeCmdletsLeft: 9223372036854775807/Unlimited
CmdletTimePeriod: 5
DestructiveCmdletsLeft: 60/Unlimited
DestructiveCmdletTimePeriod: Unlimited
QueueDepth: Unlimited
MaxRunspaces: 5
MaxRunspacesTimePeriod: 60
LastTimeFrameUpdate: 4/23/2013 8:48:20 PM
LastTimeFrameUpdateDestructiveCmdlets: 4/23/2013 8:40:36 PM
LastTimeFrameUpdateMaxRunspaces: 4/23/2013 8:48:08 PM
Locked: False
LockRemaining: 00:00:00 For more information, see the about_Remote_Troubleshooting Help topic
这是简化的代码(实际更复杂,但基本上就是这样):
private Collection<PSObject> GetUser(string userName, string password)
{
try
{
serverName = "https://outlook.office365.com/powershell-LiveID?PSVersion=2.0"
SecureString pass = new SecureString();
foreach (char x in password.ToCharArray())
{
pass.AppendChar(x);
}
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(
new Uri(serverName), PSNamespace, new PSCredential(userName, pass));
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
connectionInfo.SkipCNCheck = true;
connectionInfo.SkipCACheck = true;
CallContext.SetData("WSManConnectionInfo", connectionInfo);
using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
{
using (PowerShell powershell = PowerShell.Create())
{
try
{
powershell.AddCommand("Get-User");
powershell.AddArgument(userName);
runspace.Open();
powershell.Runspace = runspace;
return powershell.Invoke();
}
catch (Exception e)
{
return null;
}
finally
{
runspace.Close();
runspace.Dispose();
}
}
}
}
catch (Exception e)
{
return null;
}
}
感谢您的任何意见。
鲍里斯
答案 0 :(得分:0)
据我所知,在所述时间段内可以创建多少个运行空间是有限制的,而与运行空间是否再次拆除无关。 但是,我找不到任何文档来支持这种解释。