-
Notifications
You must be signed in to change notification settings - Fork 144
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 #613 from reshmee011/ensureowners
New script to Ensure m365 group owners are m365 group members
- Loading branch information
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
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,66 @@ | ||
--- | ||
plugin: add-to-gallery | ||
--- | ||
|
||
# Ensuring Owners Are Members | ||
|
||
## Summary | ||
|
||
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. | ||
|
||
# [PnP PowerShell](#tab/pnpps) | ||
|
||
```powershell | ||
$AdminCenterURL="https://contoso-admin.sharepoint.com/"# Connect to SharePoint Online admin center | ||
Connect-PnPOnline -Url $AdminCenterURL -Interactive | ||
$dateTime = (Get-Date).toString("dd-MM-yyyy") | ||
$invocation = (Get-Variable MyInvocation).Value | ||
$directorypath = Split-Path $invocation.MyCommand.Path | ||
$fileName = "m365OwnersNotMembers-" + $dateTime + ".csv" | ||
$OutPutView = $directorypath + "\Logs\"+ $fileName | ||
# Array to Hold Result - PSObjects | ||
$m365GroupCollection = @() | ||
#Write-host $"$ownerName not part of member in $siteUrl"; | ||
$m365Sites = Get-PnPTenantSite -Detailed | Where-Object {($_.Url -like '*/TEST-*'-or $_.Template -eq 'TEAMCHANNEL#1') -and $_.Template -ne 'RedirectSite#0' } | ||
$m365Sites | ForEach-Object { | ||
$groupId = $_.GroupId; | ||
$siteUrl = $_.Url; | ||
if($_.Template -eq "GROUP#0") | ||
{ | ||
#if owner is not part of m365 group member | ||
(Get-PnPMicrosoft365GroupOwner -Identity $groupId -ErrorAction Ignore) | foreach-object { | ||
$owner = $_; | ||
if(!(Get-PnPMicrosoft365GroupMember -Identity $groupId -ErrorAction Ignore| Where-Object {$_.DisplayName -eq $owner.DisplayName})) | ||
{ | ||
$ExportVw = New-Object PSObject | ||
$ExportVw | Add-Member -MemberType NoteProperty -name "Site URL" -value $siteUrl | ||
$ExportVw | Add-Member -MemberType NoteProperty -name "Owner Name" -value $owner.DisplayName | ||
$m365GroupCollection += $ExportVw | ||
Add-PnPMicrosoft365GroupMember -Identity $groupId -Users $owner.Email | ||
Write-host $"$owner.DisplayName has been added as member in $siteUrl"; | ||
} | ||
} | ||
} | ||
} | ||
# Export the result array to CSV file | ||
$m365GroupCollection | sort-object "Group Name" |Export-CSV $OutPutView -Force -NoTypeInformation | ||
``` | ||
|
||
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)] | ||
|
||
*** | ||
|
||
## Source Credit | ||
|
||
Sample first appeared on [Ensuring Owners Are Members](https://reshmeeauckloo.com/posts/powershell_ensureownersaremembersm365group/) | ||
|
||
## Contributors | ||
|
||
| Author(s) | | ||
| ----------------------------------------- | | ||
| [Reshmee Auckloo](https://github.com/reshmee011) | | ||
|
||
|
||
[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] | ||
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/aad-delete-m365-groups-and-sharepoint-sites" aria-hidden="true" /> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions
60
scripts/aad-ensure-ownersaremembers-m365groups/assets/sample.json
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,60 @@ | ||
[ | ||
{ | ||
"schema": null, | ||
"name": "aad-ensure-ownersaremembers-m365groups", | ||
"version": null, | ||
"source": "pnp", | ||
"title": "Ensuring m365 group owners are m365 group members", | ||
"url": "https://pnp.github.io/script-samples/aad-ensure-ownersaremembers-m365groups/README.html", | ||
"creationDateTime": "2023-10-29", | ||
"updateDateTime": "2023-10-29", | ||
"shortDescription": "Ensuring m365 group owners are m365 group members", | ||
"longDescription": ["M365 group owners are not always m365 group members 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."], | ||
"products": [ | ||
"AzureAD", | ||
"SharePoint" | ||
], | ||
"categories": [ | ||
"Governance" | ||
], | ||
"tags": [ | ||
"SharePoint Online", | ||
"Microsoft 365 Groups", | ||
"Connect-PnPOnline", | ||
"Get-PnPTenantSite", | ||
"Get-PnPMicrosoft365GroupOwner", | ||
"Get-PnPMicrosoft365GroupMember", | ||
"Add-PnPMicrosoft365GroupMember" | ||
], | ||
"metadata": [ | ||
{ | ||
"key": "PNP-POWERSHELL", | ||
"value": "2.2.0" | ||
} | ||
], | ||
"thumbnails": [ | ||
{ | ||
"type": "image", | ||
"order": 100, | ||
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/aad-ensure-ownersaremembers-m365groups/assets/preview.png", | ||
"alt": "preview image for the sample", | ||
"slides": null | ||
} | ||
], | ||
"authors": [ | ||
{ | ||
"gitHubAccount": "reshmee011", | ||
"company": "", | ||
"pictureUrl": "https://avatars.githubusercontent.com/u/7693852?v=4", | ||
"name": "Reshmee Auckloo" | ||
} | ||
], | ||
"references": [ | ||
{ | ||
"name": "Want to learn more about PnP PowerShell and the cmdlets", | ||
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.", | ||
"url": "https://aka.ms/pnp/powershell" | ||
} | ||
] | ||
} | ||
] |