Skip to content

Commit dd0ffc4

Browse files
committed
Fixup
1 parent ce13f68 commit dd0ffc4

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

scripts/aad-ensure-ownersaremembers-m365groups/README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
It may happen that owners are not members of the m365 group because of the various methods of managing M365 group permissions, such as through the Teams admin center, Microsoft Teams, SharePoint admin center, SharePoint connected sites, Planner, or scripting using PowerShell. The script will help identify these discrepancies and ensures m365 group owners are also m365 group members.
88

9+
CLI for Microsoft 365 script sample usage example:
10+
11+
![Example Screenshot of CLI for Microsoft 365 sample](assets/exampleCLI.png)
12+
913
# [PnP PowerShell](#tab/pnpps)
1014

1115
```powershell
@@ -102,30 +106,30 @@ process {
102106
$owners = m365 entra m365group user list --role Owner --groupId $groupId --output json | ConvertFrom-Json
103107
104108
foreach ($owner in $owners) {
105-
$ownerDisplayName = $owner.displayName
106-
$isMember = m365 entra m365group user list --role Member --groupId $groupId --query "[?displayName == '$ownerDisplayName']" --output json | ConvertFrom-Json
109+
$ownerUserPrincipalName = $owner.userPrincipalName
110+
$isMember = m365 entra m365group user list --role Member --groupId $groupId --query "[?userPrincipalName == '$ownerUserPrincipalName']" --output json | ConvertFrom-Json
107111
108112
if (-not $isMember) {
109-
Write-Host " Owner '$ownerDisplayName' missing from members, attempting to add..."
113+
Write-Host " Owner '$ownerUserPrincipalName' missing from members, attempting to add..."
110114
111115
$ReportItems.Add([pscustomobject]@{
112116
'Site Name' = $site.Title
113117
'Site URL' = $site.Url
114-
'Owner Name' = $ownerDisplayName
118+
'Owner Name' = $ownerUserPrincipalName
115119
})
116120
117-
$addResult = m365 entra m365group user add --role Member --groupId $groupId --userName $owner.userPrincipalName --output json 2>&1
121+
$addResult = m365 entra m365group user add --role Member --groupId $groupId --userNames $ownerUserPrincipalName --output json 2>&1
118122
119123
if ($LASTEXITCODE -ne 0) {
120-
Write-Warning "Failed to add $ownerDisplayName as member in $($site.Url). CLI returned: $addResult"
124+
Write-Warning "Failed to add $ownerUserPrincipalName as member in $($site.Url). CLI returned: $addResult"
121125
$Summary.OwnersFailed++
122126
continue
123127
}
124128
125-
Write-Host " Added $ownerDisplayName as member in $($site.Url)"
129+
Write-Host " Added $ownerUserPrincipalName as member in $($site.Url)"
126130
$Summary.OwnersAdded++
127131
} else {
128-
Write-Host " Owner '$ownerDisplayName' already a member; skipping"
132+
Write-Host " Owner '$ownerUserPrincipalName' already a member; skipping"
129133
}
130134
}
131135
}
227 KB
Loading

scripts/aad-ensure-ownersaremembers-m365groups/assets/sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
{
6666
"gitHubAccount": "Adam-it",
6767
"company": "",
68-
"pictureUrl": "https://avatars.githubusercontent.com/u/45694692?v=4",
68+
"pictureUrl": "https://avatars.githubusercontent.com/u/58668583?v=4",
6969
"name": "Adam Wójcik"
7070
}
7171
],

0 commit comments

Comments
 (0)