-
Notifications
You must be signed in to change notification settings - Fork 5
/
6-Owners.ps1
38 lines (28 loc) · 1.55 KB
/
6-Owners.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#---------------------------------------------------------------------------------------
# 6-Owners.ps1 - list and modify owners of a group
# Microsoft Teams and Office 365 Groups PowerShell Masterclass - by @magrom and @atwork
#---------------------------------------------------------------------------------------
# Get Ownerless groups (< 2 owners)
$OwnerlessGroups = [array](Get-UnifiedGroup | Where-Object {([array](Get-UnifiedGroupLinks `
-Identity $_.Id -LinkType Owners)).Count -lt 2}) | `
Select-Object Id, DisplayName, ManagedBy, WhenCreated, SMTPAddress
$OwnerlessGroups | ft
# Assign owner to the ownerless group
for ($i=0; $i -lt $OwnerlessGroups.Count; $i++)
{
Add-UnifiedGroupLinks $OwnerlessGroups.Alias -LinkType member -Links [email protected]
Add-UnifiedGroupLinks $OwnerlessGroups.Alias -LinkType Owner -Links [email protected]
}
# Modify owner of an existing group. The new owner must already be a member!
Get-UnifiedGroup | ? {$_.DisplayName -like 'My*'}
$group = "My Monday Project"
Add-UnifiedGroupLinks $group -LinkType Member -Links [email protected]
Add-UnifiedGroupLinks $group -LinkType Owner -Links [email protected]
# Get all groups or a specific group
Get-AzureADGroup | ? {$_.DisplayName -eq $group}
$groupid = 'ff4006fa-199b-4e01-92f5-4d93c413dcf2'
Get-TeamUser -GroupId $groupid
# Remove user: This might take some minutes...
Remove-TeamUser -GroupId $groupid -User [email protected]
# Check the result
Get-TeamUser -GroupId $groupid