Exchange 2010 Powershell脚本攻略(十四)

enable-FederatedDeliveryMailbox

$ErrorActionPreference = "SilentlyContinue"

# check syntax

if (!$args -or ($args.Length -ne 3 -and $args.Length -ne 1))

{

write-host "You need to run this script after you have configured Federated Delivery using New/Set-OrganizationRelationship task. This script needs to be run at both tenant side and on-premise side.";

write-host "Tenant side: enable-FederatedDeliveryMailbox.ps1 .";

write-host "OnPremise side: enable-FederatedDeliveryMailbox.ps1 .";

exit

}

$isDataCenter = $args.Length -eq 3

if ($isDataCenter)

{

write-host "Running on Data Center"

$organizationFederatedMailbox = $(Get-TransportConfig -Identity $args[2]).OrganizationFederatedMailbox

# OrganizationFederatedMailbox must be set.

if ( ($organizationFederatedMailbox -eq $null) -or (!$organizationFederatedMailbox.IsValidAddress) )

{

write-host "Transport Settings must have OrganizationFederatedMailbox set."

exit

}

$mailboxId = $args[2] + "" + $organizationFederatedMailbox.ToString()

write-host "Searching for existing Federated Delivery Mailbox with identity" $mailboxId

$error.Clear()

$mailbox = Get-Mailbox -Arbitration -Identity:$mailboxId;

if ($error.Count -gt 0)

{

write-host "Failed to read mailbox information" $error[0].Exception;

exit;

}

else

{

$error.Clear();

$organizationFederatedMailboxLiveId = $mailbox.WindowsLiveID

if ( ($organizationFederatedMailboxLiveId -eq $null) -or (!$organizationFederatedMailboxLiveId.IsValidAddress) )

{

write-host "Federated Delivery Mailbox is not Live enabled. Creating LiveID for Federated Delivery Mailbox" $organizationFederatedMailbox.ToString()

$pwd = (ConvertTo-SecureString $args[1] -AsPlainText -Force)

$mailbox = Set-Mailbox -Arbitration -Identity $mailboxId -WindowsLiveId:$organizationFederatedMailbox.ToString() -Password $pwd -Force

if ($error.Count -gt 0)

{

write-host "Failed to Live enable Federated Delivery Mailbox because of " $error[0].Exception;

exit;

}

else

{

write-host "Successfully Live enabled Federated Delivery Mailbox";

}

}

else

{

write-host "Federated Delivery Mailbox already Live enabled."

}

}

}

else

{

write-host "Running in on-premise setup"

$organizationFederatedMailbox = $(Get-TransportConfig).OrganizationFederatedMailbox

# OrganizationFederatedMailbox must be set.

if ( ($organizationFederatedMailbox -eq $null) -or (!$organizationFederatedMailbox.IsValidAddress) )

{

write-host "Transport Settings must have OrganizationFederatedMailbox set."

exit

}

}

# Get the organization relationship setting based on organization relationship identity passed in as parameter.

$organizationRelationship = Get-OrganizationRelationship -Identity:$args[0];

if ($organizationRelationship -eq $null)

{

write-host "There is no organization relationship based on the identity" $args[0]

exit

}

# Provision the remote domain setting for this org.

write-host "Provisoning Remote Domains ........"

$remoteDomains = $null

if ($isDataCenter)

{

$remoteDomains = Get-RemoteDomain -Organization $args[2]

}

else

{

$remoteDomains = Get-RemoteDomain

}

foreach ($domain in $organizationRelationship.DomainNames)

{

$domainName = $domain.ToString()

$foundMatch = $false

# Go through existing remote domains to find match with organization relationship domains

foreach ($remoteDomain in $remoteDomains)

{

$match = $remoteDomain.DomainName.match($domainName)

if ($match -gt 0)

{

# For the one that matches (more than wild card matching, i.e. matching to *), we should set the following properties to make cross premise mail look like internal.

write-host "Remote domain" $remoteDomain.Name "with domain" $remoteDomain.domainname.address "matches organization relationship domain" $domainName

$foundMatch = $true

$remoteDomain | Set-RemoteDomain -AllowedOOFType InternalLegacy -AutoForwardEnabled $true -AutoReplyEnabled $true -TNEFEnabled $true

}

}

if ($foundMatch -eq $false)

{

# Create new remote domain entry and prep for cross premise federated delivery.

write-host "Creating a new remote domain for" $domainName

$newRemoteDomain = $null

if ($isDataCenter)

{

$newRemoteDomain = New-RemoteDomain -Name $domainName -DomainName $domainName -Organization $args[2]

}

else

{

$newRemoteDomain = New-RemoteDomain -Name $domainName -DomainName $domainName

}

$newRemoteDomain | Set-RemoteDomain -AllowedOOFType InternalLegacy -AutoForwardEnabled $true -AutoReplyEnabled $true -TNEFEnabled $true

}

}

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23700676/viewspace-1052340/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23700676/viewspace-1052340/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值