首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell -为什么Set-CASMailbox引发的异常没有被捕获?

Powershell -为什么Set-CASMailbox引发的异常没有被捕获?
EN

Stack Overflow用户
提问于 2014-06-25 17:07:09
回答 1查看 1.5K关注 0票数 0

我有一个Powershell脚本,它运行在安装了Exchange 2010控制台的Windows2008ExchangeServer服务器上。脚本pmduaactivesync.ps1,是从任务调度程序运行的,因此必须使用奇怪的命令来调用它,而不是直接调用它。以下是它的运行方式:

代码语言:javascript
复制
powershell -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\v14\bin\exshell.psc1" -exec bypass -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\Bin\Exchange.ps1'; &'C:\dev\csom\pmduaactivesync.ps1'" 

脚本正在作为服务帐户运行,并且该帐户拥有在Exchange环境中进行更改所需的所有访问权限。

现在,在脚本中,我曾经尝试将邮箱上的Exchange ActiveSync属性设置为True。这是代码的那一部分

代码语言:javascript
复制
# Try setting ActiveSync to true
try {
  Set-CASMailbox -Identity $tempUsername -ActiveSyncEnabled $true 
  if ($?) {
    # Set ASChangeValue to 1 (to be used when updating SP List)
    $ASChangeValue="1"
  } else {
    throw $error[0].Exception
  }
} catch {
  Write-Host "Exception caught with 'Set-CASMailbox -Identity $tempUsername -ActiveSyncEnabled $true' command." -ForegroundColor Red
  Write-Host "Exception Type: $($_.Exception.GetType().FullName)" -ForegroundColor Red
  Write-Host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red
  $ASChangeValue="8"
}

在脚本中,我还使用Start-Transcript cmdlet创建了一个记录。

这是我的问题。Set-CASMailbox cmdlet抛出一个错误,如下所示:

代码语言:javascript
复制
WARNING: The cmdlet extension agent with the index 1 has thrown an exception in OnComplete(). The exception is: 
System.InvalidOperationException: Operation is not valid due to the current state of the object.

   at Microsoft.Exchange.Data.Storage.ExchangePrincipal.get_ServerFullyQualifiedDomainName()

   at Microsoft.Exchange.Data.Storage.MailboxSession.Initialize(MapiStore linkedStore, LogonType logonType, 
ExchangePrincipal owner, DelegateLogonUser delegateUser, Object identity, OpenMailboxSessionFlags flags, 
GenericIdentity auxiliaryIdentity)

   at Microsoft.Exchange.Data.Storage.MailboxSession.<>c__DisplayClass12.<CreateMailboxSession>b__10(MailboxSession 
mailboxSession)

   at Microsoft.Exchange.Data.Storage.MailboxSession.InternalCreateMailboxSession(LogonType logonType, 
ExchangePrincipal owner, CultureInfo cultureInfo, String clientInfoString, IAccountingObject budget, Action`1 
initializeMailboxSession, InitializeMailboxSessionFailure initializeMailboxSessionFailure)

   at Microsoft.Exchange.Data.Storage.MailboxSession.CreateMailboxSession(LogonType logonType, ExchangePrincipal owner,
 DelegateLogonUser delegateUser, Object identity, OpenMailboxSessionFlags flags, CultureInfo cultureInfo, String 
clientInfoString, PropertyDefinition[] mailboxProperties, IList`1 foldersToInit, GenericIdentity auxiliaryIdentity, 
IAccountingObject budget)

   at Microsoft.Exchange.Data.Storage.MailboxSession.ConfigurableOpen(ExchangePrincipal mailbox, MailboxAccessInfo 
accessInfo, CultureInfo cultureInfo, String clientInfoString, LogonType logonType, PropertyDefinition[] 
mailboxProperties, InitializationFlags initFlags, IList`1 foldersToInit, IAccountingObject budget)

   at Microsoft.Exchange.Data.Storage.MailboxSession.OpenAsSystemService(ExchangePrincipal mailboxOwner, CultureInfo 
cultureInfo, String clientInfoString)

   at Microsoft.Exchange.ProvisioningAgent.MailboxLoggerFactory.XsoMailer.Log(AdminLogMessageData data, 
LogMessageDelegate logMessage)

   at Microsoft.Exchange.ProvisioningAgent.AdminLogProvisioningHandler.OnComplete(Boolean succeeded, Exception e)

   at Microsoft.Exchange.Provisioning.ProvisioningLayer.OnComplete(Task task, Boolean succeeded, Exception exception)

我不是100%这样做的,但是由于错误引用了“带有索引1的cmdlet扩展代理”,所以我运行了Get-CmdletExtensionAgent来查看可能是什么。在运行该命令之后,假设我正确地读取了它,它将引用Query代理

代码语言:javascript
复制
>Get-CmdletExtensionAgent | Format-Table Name, Enabled, Priority
Name                                Enabled    Priority
----                                -------    --------
Admin Audit Log Agent                  True         255
Query Base DN Agent                    True           1
Rus Agent                              True           2
Mailbox Resources Management Agent     True           3
Provisioning Policy Agent              True           4
OAB Resources Management Agent         True           5
Scripting Agent                       False           6
Mailbox Creation Time Agent            True           0

这是我的大问题,

为什么这个例外没有被抓住?

在我的脚本后面,$ASChangeValue仍然被设置为1,而不是8。如果能在这方面提供任何帮助,谢谢。

EN

回答 1

Stack Overflow用户

发布于 2014-06-26 08:52:55

-ErrorAction Stop添加到Set-CASMailbox

代码语言:javascript
复制
Set-CASMailbox -Identity $tempUsername -ActiveSyncEnabled $true -ErrorAction Stop
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24414663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档