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/