Exchange 2010 Powershell指令碼攻略(十三)
enable-CrossForestConnector
Param(
[Microsoft.Exchange.Data.Directory.SystemConfiguration.ADConfigurationObject] $instance = $null,
[string] $connectorName = $null,
[switch] $help,
[switch] $genericMTA
)
begin
{
#
#
function Usage()
{
write-host @'
Adjusts the permissions on a Send Connector for Cross Forest trust.
Enable-CrossForestConnector [-help] [-instance $x] [-connectorName "foo"] [-genericMTA]
-instance A SendConnector instance. Usually this is obtained from
get-SendConnector and used in place of -connectorName.
-connectorName The identity/Name of the connector to modify.
-genericMTA Set the permissions necessary for Exchange 2003 or another type of MTA.
Examples
get-sendConnector "OneSendConnector" | enable-CrossforestConnector
enable-CrossforestConnector -instance $(get-sendconnector "CfSendConnector")
'@
}
#
#
# The identity of the connector to find.
#
#
function FindInstance([string] $name)
{
# Attempt to find it as a Receive Connector and suppress the failure behavior as it could be a send connector.
$connector= Get-ReceiveConnector $name -ErrorAction SilentlyContinue
if (!$connector)
{
# Attempt to find it as a Send Connector and suppress the failure behavior.
$connector = Get-SendConnector $name -ErrorAction SilentlyContinue
}
# return the connector.
$connector -as [Microsoft.Exchange.Data.Directory.SystemConfiguration.ADConfigurationObject]
}
#
#
# The connector instance to modify
# The user or USG that is being added
# An array of new rights that are needed
#
#
# be generated by analyzing the existing rights.
#
function FilterNewRights([Microsoft.Exchange.Data.Directory.SystemConfiguration.ADConfigurationObject] $instance, [string] $user, [object[]]$newRights)
{
trap [Microsoft.Exchange.Configuration.Tasks.ManagementObjectNotFoundException]
{
$Script:invalidUser = $true
continue;
}
# find all the existing rights for the specified user.
$rules = get-adpermission -Identity $instance.Identity -user $user -ErrorAction SilentlyContinue
if ($Script:invalidUser)
{
return @()
}
# flatten this list into one and skip deny rules.
$oldRights = @()
if ($rules -ne $null)
{
foreach($rule in $rules)
{
if ($rule.Deny -or !$rule.ExtendedRights)
{
continue
}
foreach($right in $rule.ExtendedRights)
{
$oldRights += $right.ToString()
}
}
}
# Create a new list by filtering out existing rights.
$applyRights = @()
foreach ($right in $newRights)
{
if ($oldRights -notcontains $right)
{
[Microsoft.Exchange.Configuration.Tasks.ExtendedRightIdParameter] $temp = [Microsoft.Exchange.Configuration.Tasks.ExtendedRightIdParameter]::Parse($right)
$applyRights += $temp;
}
}
# Return the applyRights.
$applyRights;
}
}
process
{
if ($help -or $args -contains "-?")
{
Usage
return
}
$User = "NT AUTHORITYANONYMOUS LOGON"
if (!$instance)
{
$instance = $_
}
if (!$instance)
{
if ($connectorName -eq "")
{
throw "Either ConnectorName or Identity must be specified."
}
$instance = FindInstance $connectorName
}
if (!$instance)
{
throw "No connector found that matches '$connectorName'"
}
$invalidUser = $false
$applyRights = @()
if ($instance -is [Microsoft.Exchange.Data.Directory.SystemConfiguration.SendConnector])
{
if ($genericMTA)
{
$newRights = @(
"ms-Exch-Send-Headers-Routing",
"ms-Exch-SMTP-Send-Exch50"
)
}
else
{
$newRights = @(
"ms-Exch-Send-Headers-Routing",
"ms-Exch-Send-Headers-Forest",
"ms-Exch-Send-Headers-Organization"
)
}
$applyRights = FilterNewRights $instance $user $newRights
}
else
{
throw "The found instance was not a SendConnector."
}
if ($invalidUser)
{
throw $error[0].Exception
}
if ($applyRights -ne $null -and $applyRights -ne @())
{
write-host "Connector:" $instance.Identity
Add-ADPermission -Identity $instance.Identity -user $user -ExtendedRights $applyRights
}
else
{
write-host "Connector:" $instance.Identity
write-host ""
write-host "All rights necessary already exist for '$user'"
}
}
[@more@]來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23700676/viewspace-1052339/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Exchange 2010 Powershell指令碼攻略(十五)指令碼
- Exchange 2010 Powershell指令碼攻略(十四)指令碼
- Exchange 2010 Powershell指令碼攻略(十二)指令碼
- Exchange 2010 Powershell指令碼攻略(十一)指令碼
- Exchange 2010 Powershell指令碼攻略(十)指令碼
- Exchange 2010 Powershell指令碼攻略(九)指令碼
- Exchange 2010 Powershell指令碼攻略(八)指令碼
- Exchange 2010 Powershell指令碼攻略(七)指令碼
- Exchange 2010 Powershell指令碼攻略(六)指令碼
- Exchange 2010 Powershell指令碼攻略(五)指令碼
- Exchange 2010 Powershell指令碼攻略(四)指令碼
- Exchange 2010 Powershell指令碼攻略(三)指令碼
- Exchange 2010 Powershell指令碼攻略(二)指令碼
- Exchange 2010 Powershell指令碼攻略(一)指令碼
- powershell指令碼指令碼
- PowerShell 指令碼中的密碼指令碼密碼
- PowerShell 指令碼執行策略指令碼
- powershell重新命名指令碼指令碼
- Exchange 2010搭建
- Bash指令碼debug攻略指令碼
- 開機自啟動Powershell指令碼指令碼
- linux shell 指令碼攻略筆記Linux指令碼筆記
- 【黑客基礎】Windows PowerShell 指令碼學習(上)黑客Windows指令碼
- 最簡單的一個powershell的指令碼指令碼
- Exchange 2010需要的網路埠
- 微軟宣佈全新命令列+指令碼工具:PowerShell 7微軟命令列指令碼
- 五個實用的SQL Server PowerShell指令碼OMSQLServer指令碼
- 利用powershell指令碼Windows hosts記錄替換IP指令碼Windows
- Win10使用Powershell提示禁止執行指令碼怎麼辦 Win10使用Powershell提示禁止執行指令碼如何解決Win10指令碼
- shell指令碼攻略--DNS正向解析一鍵部署指令碼DNS
- 利用 Powershell 編寫簡單的瀏覽器指令碼瀏覽器指令碼
- 【連結】LINUX SHELL指令碼攻略筆記[速查]Linux指令碼筆記
- 《Linux Shell指令碼攻略(第2版)》書評Linux指令碼
- nuget打包檔案丟失如何使用powershell指令碼解決指令碼
- 使用VSCode遠端除錯惡意Powershell指令碼VSCode除錯指令碼
- 【VMware VCF】使用 PowerShell 指令碼管理 SDDC Manager 中的軟體包。指令碼
- PowerShell 指令碼來監控 CPU、記憶體和磁碟使用情況:指令碼記憶體
- linux shell 指令碼攻略學習6-xargs詳解Linux指令碼