Skip to content

Commit 5c5abb2

Browse files
authored
Improve reliability by using GroupId directly in manage-creation-of-groups article
Update the example cmdlet to reference the `GroupId` directly instead of resolving it via the group `DisplayName`. Relying on `Where-Object` with `DisplayName` can return `null` or multiple results when groups share the same name, which may lead to incorrect behavior or script failures. Using `GroupId` ensures accuracy and consistency.
1 parent d6c1a41 commit 5c5abb2

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

microsoft-365/solutions/manage-creation-of-groups.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ Use the [Microsoft Graph PowerShell](/powershell/microsoftgraph/installation) **
102102

103103
Copy the following script into a text editor, such as Notepad, or the [Windows PowerShell ISE](/powershell/scripting/components/ise/introducing-the-windows-powershell-ise).
104104

105-
Replace *\<GroupName\>* with the name of the group that you created. For example:
105+
Replace *\<GroupId\>* with the name of the group that you created. For example:
106106

107-
`$GroupName = "Group Creators"`
107+
`$GroupId = "22c74eb7-e0d4-439a-998d-002e2ff7c874"`
108108

109109
Save the file as GroupCreators.ps1.
110110

@@ -122,7 +122,7 @@ Import-Module Microsoft.Graph.Beta.Groups
122122
123123
Connect-MgGraph -Scopes "Directory.ReadWrite.All", "Group.Read.All"
124124
125-
$GroupName = ""
125+
$GroupId = ""
126126
$AllowGroupCreation = "False"
127127
128128
$settingsObjectID = (Get-MgBetaDirectorySetting | Where-object -Property Displayname -Value "Group.Unified" -EQ).id
@@ -144,9 +144,6 @@ if(!$settingsObjectID)
144144
$settingsObjectID = (Get-MgBetaDirectorySetting | Where-object -Property Displayname -Value "Group.Unified" -EQ).Id
145145
}
146146
147-
148-
$groupId = (Get-MgBetaGroup -all | Where-object {$_.displayname -eq $GroupName}).Id
149-
150147
$params = @{
151148
templateId = "62375ab9-6b52-47ed-826b-58e47e0e304b"
152149
values = @(
@@ -156,7 +153,7 @@ $params = @{
156153
}
157154
@{
158155
name = "GroupCreationAllowedGroupId"
159-
value = $groupId
156+
value = $GroupId
160157
}
161158
)
162159
}

0 commit comments

Comments
 (0)