在powershell

时间:2016-01-07 15:10:03

标签: powershell exchange-server

有没有办法在没有收到非邮箱帐户的所有错误的情况下执行此操作...

我发现为了在AD中备份已禁用的用户帐户的邮箱,我需要执行以下操作:

$baseou = "OU=Companies,DC=triangle,DC=com"
$MyDisabledUsers = Search-ADAccount -SearchBase $baseou -AccountDisabled | select name
$MyListOfDisabledUsersThatHaveMailboxes = foreach ($mbx in $MyDisabledUsers) {Get-Mailbox  $mbx.name -ErrorAction SilentlyContinue}
foreach ($AllMailboxes in $MyListOfDisabledUsersThatHaveMailboxes) { New-MailboxExportRequest -Mailbox $AllMailboxes -FilePath "\\it-fs02\pst$\$($AllMailboxes.Database)-$($AllMailboxes.DisplayName)-$($AllMailboxes.Alias).pst" }

但是,即使它有效,我也会收到每个没有邮箱的已禁用用户帐户的错误。

  

警告:索引为0的cmdlet扩展代理程序在OnComplete()中引发了异常。例外是:   System.InvalidOperationException:由于操作无效   对象的当前状态。在   Microsoft.Exchange.Data.Storage.ExchangePrincipal.get_ServerFullyQualifiedDomainName()   在Microsoft.Exchange.Data.Storage.MailboxSession.Initialize(MapiStore   linkedStore,LogonType logonType,ExchangePrincipal所有者,   DelegateLogonUser delegateUser,Object identity,OpenMailb   oxSessionFlags标志,GenericIdentity auxiliaryIdentity)at   Microsoft.Exchange.Data.Storage.MailboxSession<> c__DisplayClass12.b__10(MailboxSession   mailboxSession)at   Microsoft.Exchange.Data.Storage.MailboxSession.InternalCreateMailboxSession(登录类型   logonType,ExchangePrincipal所有者,CultureInfo cultureInfo,String   clientInfoString,IAccountingOb ject budget,Action 1 initializeMailboxSession, InitializeMailboxSessionFailure initializeMailboxSessionFailure) at Microsoft.Exchange.Data.Storage.MailboxSession.CreateMailboxSession(LogonType logonType, ExchangePrincipal owner, DelegateLogonUser delegateUser, Object identity, OpenMailboxSessionFlag s flags, CultureInfo cultureInfo, String clientInfoString, PropertyDefinition[] mailboxProperties, IList 1 foldersToInit,GenericIdentity   auxiliaryIdentity,IAccountingObject预算)at   Microsoft.Exchange.Data.Storage.MailboxSession.ConfigurableOpen(ExchangePrincipal   mailbox,MailboxAccessInfo accessInfo,CultureInfo cultureInfo,String   clientInfoString,LogonType logo nType,PropertyDefinition []   mailboxProperties,InitializationFlags initFlags,IList`1   foldersToInit,IAccountingObject预算)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(布尔   成功,例外e)at   Microsoft.Exchange.Provisioning.ProvisioningLayer.OnComplete(任务   task,布尔成功,异常异常)

它有效,但我真的不希望错误显示。

过去,其他人被告知要使用以下命令:

foreach ($AllMailboxes in (Get-Mailbox -Filter {(ExchangeUserAccountControl -eq 'AccountDisabled' -and ResourceType -ne 'Room' -and SamAccountName -notlike 'TDRK_*' -and DisplayName -notlike 'Discovery*')})) { New-MailboxExportRequest -Mailbox $AllMailboxes -FilePath "\\it-fs02\pst$\$($AllMailboxes.Database)-$($AllMailboxes.DisplayName)-$($AllMailboxes.Alias).pst" }

虽然这有效,但它不会导出所有具有邮箱的已禁用用户帐户。只交换不同的交换禁用邮箱。

任何建议。

0 个答案:

没有答案