Skip to content

Commit 4347804

Browse files
authored
Merge pull request #104054 from riantu/patch-20
Update script to test the presence of a directory setting
2 parents c46bbed + 4375dd3 commit 4347804

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

articles/active-directory/hybrid/how-to-connect-modify-group-writeback.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,28 @@ To configure directory settings to disable automatic writeback of newly created
3636
- PowerShell: Use the [Microsoft Graph PowerShell SDK](/powershell/microsoftgraph/installation?view=graph-powershell-1.0&preserve-view=true). For example:
3737

3838
```PowerShell
39-
# Import Module
40-
Import-Module Microsoft.Graph.Identity.DirectoryManagement
41-
42-
#Connect to MgGraph with necessary scope and select the Beta API Version
43-
Connect-MgGraph -Scopes Directory.ReadWrite.All
44-
Select-MgProfile -Name beta
45-
39+
# Import Module
40+
Import-Module Microsoft.Graph.Identity.DirectoryManagement
41+
42+
#Connect to MgGraph with necessary scope and select the Beta API Version
43+
Connect-MgGraph -Scopes Directory.ReadWrite.All
44+
Select-MgProfile -Name beta
45+
46+
# Verify if "Group.Unified" directory settings exist
47+
$DirectorySetting = Get-MgDirectorySetting | Where-Object {$_.DisplayName -eq "Group.Unified"}
48+
49+
# If "Group.Unified" directory settings exist, update the value for new unified group writeback default
50+
if ($DirectorySetting) {
51+
$DirectorySetting.Values | ForEach-Object {
52+
if ($_.Name -eq "NewUnifiedGroupWritebackDefault") {
53+
$_.Value = "false"
54+
}
55+
}
56+
Update-MgDirectorySetting -DirectorySettingId $DirectorySetting.Id -BodyParameter $DirectorySetting
57+
}
58+
else
59+
{
60+
# In case the directory setting doesn't exist, create a new "Group.Unified" directory setting
4661
# Import "Group.Unified" template values to a hashtable
4762
$Template = Get-MgDirectorySettingTemplate | Where-Object {$_.DisplayName -eq "Group.Unified"}
4863
$TemplateValues = @{}
@@ -52,6 +67,7 @@ To configure directory settings to disable automatic writeback of newly created
5267
5368
# Update the value for new unified group writeback default
5469
$TemplateValues["NewUnifiedGroupWritebackDefault"] = "false"
70+
5571
# Create a directory setting using the Template values hashtable including the updated value
5672
$params = @{}
5773
$params.Add("TemplateId", $Template.Id)
@@ -60,6 +76,7 @@ To configure directory settings to disable automatic writeback of newly created
6076
$params.Values += @(@{Name = $_; Value = $TemplateValues[$_]})
6177
}
6278
New-MgDirectorySetting -BodyParameter $params
79+
}
6380
```
6481

6582
> [!NOTE]

0 commit comments

Comments
 (0)