我有一个Powershell脚本,它运行在安装了Exchange 2010控制台的Windows2008ExchangeServer服务器上。脚本pmduaactivesync.ps1,是从任务调度程序运行的,因此必须使用奇怪的命令来调用它,而不是直接调用它。以下是它的运行方式:
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。这是代码的那一部分
# 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抛出一个错误,如下所示:
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代理。
>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。如果能在这方面提供任何帮助,谢谢。
发布于 2014-06-26 08:52:55
将-ErrorAction Stop添加到Set-CASMailbox
Set-CASMailbox -Identity $tempUsername -ActiveSyncEnabled $true -ErrorAction Stophttps://stackoverflow.com/questions/24414663
复制相似问题