先日の記事を投稿したところ、友人より「GUIだと手順が面倒だし、美しくない」と優しいコメントを頂きましたので、PowerShellで書き直してみました。
これだと既存のコネクタが一時的にDisableになったりしませんし、後から自分で追加したカスタムルールということが明示できるので今後のソフトウェアのアップデートなどの際に分かりやすいかもしれません。
※こちらのスクリプトはExchangeスキーマを拡張していない環境では実施しないで下さい(参照先のルールが存在しませんので)。また、マルチドメイン環境には対応していません。
# Get Connector ID
$conID = (Get-ADSyncConnector | ? {$_.Type -eq "AD"} | select -first 1).Identifier.Guid
New-ADSyncRule `
-Name 'Custom rule from AD(Exchange)' `
-Description 'User object with Exchange schema in Active Directory. (without mailNickname)' `
-Direction 'Inbound' `
-Precedence 200 `
-SourceObjectType 'user' `
-TargetObjectType 'person' `
-Connector $conID `
-LinkType 'Join' `
-SoftDeleteExpiryInterval 0 `
-ImmutableTag 'Custom rule from AD(Exchange)' `
-OutVariable syncRule
# Get attribute flow mapping from existing rule "In from AD - User Exchange"
$AttributeFlowMappings = (Get-ADSyncRule | ? {$_.Name -eq "In from AD - User Exchange"}).AttributeFlowMappings
foreach ($mapping in $AttributeFlowMappings){
Add-ADSyncAttributeFlowMapping -SynchronizationRule $syncRule[0] $mapping
}
New-Object `
-TypeName 'Microsoft.IdentityManagement.PowerShell.ObjectModel.ScopeCondition' `
-ArgumentList 'mailNickname','','ISNULL' `
-OutVariable condition
Add-ADSyncScopeConditionGroup `
-SynchronizationRule $syncRule[0] `
-ScopeConditions @($condition[0]) `
-OutVariable syncRule
Add-ADSyncRule -SynchronizationRule $syncRule[0]