PowerShell Runspace to Exchange Online Budget Exceeded Error
本文关键字:Budget Exceeded Error Online Exchange Runspace to PowerShell | 更新日期: 2023-09-27 18:10:28
我有一个在Exchange Server上以编程方式调用PowerShell命令的应用程序。将应用程序连接到Exchange在线服务器outlook.office365.com是成功的,并且调用单个命令有效,但在短时间内按顺序发送多个命令,服务器会阻塞并回复以下消息。
我试过用runspace。关闭和运行空间。处置,但没有效果。
从下面的消息中,我看到在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;
}
}
谢谢你的建议。
鲍里斯
正如我所理解的,在上述时间段内可以创建多少个运行空间是有限制的,无论运行空间是否再次被拆除。但是,我没有找到任何文档来支持这种解释。