-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1605 from jemrobinson/add-update-aad-sync-rule
Pulumi: Add update AAD sync script
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
data_safe_haven/resources/desired_state_configuration/UpdateAADSyncRule.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Import-Module -Name "C:\Program Files\Microsoft Azure AD Sync\Bin\ADSync" -Force -ErrorAction Stop | ||
|
||
# Create a new rule that is a copy of the default rule | ||
$defaultRule = Get-ADSyncRule | Where-Object { $_.Name -eq "Out to AAD - User Join" } | ||
$newRule = New-ADSyncRule ` | ||
-Name 'Out to AAD - User Join' ` | ||
-Description $defaultRule.Description ` | ||
-Direction 'Outbound' ` | ||
-Precedence $defaultRule.Precedence ` | ||
-PrecedenceAfter $defaultRule.PrecedenceAfter ` | ||
-PrecedenceBefore $defaultRule.PrecedenceBefore ` | ||
-SourceObjectType $defaultRule.SourceObjectType ` | ||
-TargetObjectType $defaultRule.TargetObjectType ` | ||
-Connector $defaultRule.Connector ` | ||
-LinkType $defaultRule.LinkType ` | ||
-SoftDeleteExpiryInterval $defaultRule.SoftDeleteExpiryInterval ` | ||
-ImmutableTag '' ` | ||
-EnablePasswordSync | ||
|
||
# Copy all flow mappings except the usage location one | ||
foreach ($flow in ($defaultRule.AttributeFlowMappings | Where-Object { $_.Destination -ne "usageLocation" })) { | ||
$params = @{ | ||
Destination = $flow.Destination | ||
FlowType = $flow.FlowType | ||
ValueMergeType = $flow.ValueMergeType | ||
} | ||
if ($flow.Source) { $params["Source"] = $flow.Source } | ||
if ($flow.Expression) { $params["Expression"] = $flow.Expression } | ||
$null = Add-ADSyncAttributeFlowMapping -SynchronizationRule $newRule @params | ||
} | ||
|
||
# Set the usage location flow mapping manually | ||
$null = Add-ADSyncAttributeFlowMapping -SynchronizationRule $newRule -Source @('c') -Destination 'usageLocation' -FlowType 'Direct' -ValueMergeType 'Update' | ||
|
||
# Add appropriate scope and join conditions | ||
$newRule.JoinFilter = $defaultRule.JoinFilter | ||
$newRule.ScopeFilter = $defaultRule.ScopeFilter | ||
|
||
# Remove the old rule and add the new one | ||
$null = Remove-ADSyncRule -SynchronizationRule $defaultRule | ||
Add-ADSyncRule -SynchronizationRule $newRule |