Skip to content

Commit 83ae30e

Browse files
authored
Update how-to-connect-modify-group-writeback.md
Update outdated scripts to use the new MSGraph beta SDK
1 parent 5baa488 commit 83ae30e

File tree

1 file changed

+51
-48
lines changed

1 file changed

+51
-48
lines changed

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

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -32,50 +32,54 @@ If the original version of group writeback is already enabled and in use in your
3232

3333
To configure directory settings to disable automatic writeback of newly created Microsoft 365 groups, use one of these methods:
3434

35-
- PowerShell: Use the [Microsoft Graph PowerShell SDK](/powershell/microsoftgraph/installation?view=graph-powershell-1.0&preserve-view=true). For example:
35+
- PowerShell: Use the [Microsoft Graph Beta PowerShell SDK](/powershell/microsoftgraph/installation?view=graph-powershell-1.0&preserve-view=true). For example:
3636

3737
```PowerShell
38-
# Import Module
39-
Import-Module Microsoft.Graph.Identity.DirectoryManagement
40-
41-
#Connect to MgGraph with necessary scope and select the Beta API Version
42-
Connect-MgGraph -Scopes Directory.ReadWrite.All
43-
Select-MgProfile -Name beta
44-
45-
# Verify if "Group.Unified" directory settings exist
46-
$DirectorySetting = Get-MgDirectorySetting | Where-Object {$_.DisplayName -eq "Group.Unified"}
47-
48-
# If "Group.Unified" directory settings exist, update the value for new unified group writeback default
49-
if ($DirectorySetting) {
50-
$DirectorySetting.Values | ForEach-Object {
51-
if ($_.Name -eq "NewUnifiedGroupWritebackDefault") {
52-
$_.Value = "false"
53-
}
54-
}
55-
Update-MgDirectorySetting -DirectorySettingId $DirectorySetting.Id -BodyParameter $DirectorySetting
56-
}
57-
else
58-
{
59-
# In case the directory setting doesn't exist, create a new "Group.Unified" directory setting
60-
# Import "Group.Unified" template values to a hashtable
61-
$Template = Get-MgDirectorySettingTemplate | Where-Object {$_.DisplayName -eq "Group.Unified"}
62-
$TemplateValues = @{}
63-
$Template.Values | ForEach-Object {
64-
$TemplateValues.Add($_.Name, $_.DefaultValue)
38+
# Import Module
39+
Import-Module Microsoft.Graph.Beta.Identity.DirectoryManagement
40+
41+
#Connect to MgGraph with necessary scope
42+
Connect-MgGraph -Scopes Directory.ReadWrite.All
43+
44+
45+
# Verify if "Group.Unified" directory settings exist
46+
$DirectorySetting = Get-MgBetaDirectorySetting| Where-Object {$_.DisplayName -eq "Group.Unified"}
47+
48+
# If "Group.Unified" directory settings exist, update the value for new unified group writeback default
49+
if ($DirectorySetting)
50+
{
51+
$params = @{
52+
Values = @(
53+
@{
54+
Name = "NewUnifiedGroupWritebackDefault"
55+
Value = $false
56+
}
57+
)
58+
}
59+
Update-MgBetaDirectorySetting -DirectorySettingId $DirectorySetting.Id -BodyParameter $params
6560
}
66-
67-
# Update the value for new unified group writeback default
68-
$TemplateValues["NewUnifiedGroupWritebackDefault"] = "false"
61+
else
62+
{
63+
# In case the directory setting doesn't exist, create a new "Group.Unified" directory setting
64+
# Import "Group.Unified" template values to a hashtable
65+
$Template = Get-MgBetaDirectorySettingTemplate | Where-Object {$_.DisplayName -eq "Group.Unified"}
66+
$TemplateValues = @{}
67+
$Template.Values | ForEach-Object {
68+
$TemplateValues.Add($_.Name, $_.DefaultValue)
69+
}
6970
70-
# Create a directory setting using the Template values hashtable including the updated value
71-
$params = @{}
72-
$params.Add("TemplateId", $Template.Id)
73-
$params.Add("Values", @())
74-
$TemplateValues.Keys | ForEach-Object {
75-
$params.Values += @(@{Name = $_; Value = $TemplateValues[$_]})
71+
# Update the value for new unified group writeback default
72+
$TemplateValues["NewUnifiedGroupWritebackDefault"] = $false
73+
74+
# Create a directory setting using the Template values hashtable including the updated value
75+
$params = @{}
76+
$params.Add("TemplateId", $Template.Id)
77+
$params.Add("Values", @())
78+
$TemplateValues.Keys | ForEach-Object {
79+
$params.Values += @(@{Name = $_; Value = $TemplateValues[$_]})
80+
}
81+
New-MgBetaDirectorySetting -BodyParameter $params
7682
}
77-
New-MgDirectorySetting -BodyParameter $params
78-
}
7983
```
8084

8185
> [!NOTE]
@@ -88,23 +92,22 @@ To configure directory settings to disable automatic writeback of newly created
8892
To disable writeback of all Microsoft 365 groups that were created before these modifications, use one of the following methods:
8993

9094
- Portal: Use the [Microsoft Entra admin portal](../../enterprise-users/groups-write-back-portal.md).
91-
- PowerShell: Use the [Microsoft Graph PowerShell SDK](/powershell/microsoftgraph/installation?view=graph-powershell-1.0&preserve-view=true). For example:
95+
- PowerShell: Use the [Microsoft Graph Beta PowerShell SDK](/powershell/microsoftgraph/installation?view=graph-powershell-1.0&preserve-view=true). For example:
9296

9397
```PowerShell
9498
#Import-module
95-
Import-module Microsoft.Graph
96-
97-
#Connect to MgGraph with necessary scope and select the Beta API Version
99+
Import-Module Microsoft.Graph.Beta
100+
101+
#Connect to MgGraph with necessary scope
98102
Connect-MgGraph -Scopes Group.ReadWrite.All
99-
Select-MgProfile -Name beta
100-
103+
101104
#List all Microsoft 365 Groups
102-
$Groups = Get-MgGroup -All | Where-Object {$_.GroupTypes -like "*unified*"}
103-
105+
$Groups = Get-MgBetaGroup -All | Where-Object {$_.GroupTypes -like "*unified*"}
106+
104107
#Disable Microsoft 365 Groups
105108
Foreach ($group in $Groups)
106109
{
107-
Update-MgGroup -GroupId $group.id -WritebackConfiguration @{isEnabled=$false}
110+
Update-MgBetaGroup -GroupId $group.id -WritebackConfiguration @{isEnabled=$false}
108111
}
109112
```
110113

0 commit comments

Comments
 (0)