Remove-TeamUser -GroupId 195e7e66-8dda-46e1-8ff2-ecfb2b787ba1 -User he@begone.com
where the ExternalDirectoryObjectId
attribute
of the team in question is what you use for GroupId
Get-CSOnlineUser | select name, UserPrincipalName, lineURI | ogv
one way uses Get-UnifiedGroup
$teams = Get-UnifiedGroup | Where-Object {$_.WelcomeMessageEnabled -like "False"} | select Alias, ManagedByDetails
followed by
$teams | select DisplayName, Alias, Identity, ExternalDirectoryObjectId, ManagedBy, GroupType, AccessType, ExchangeGuid | ogv
The ExternalDirectoryObjectId
attribute is important
if you want to do something like remove team members
a newer, seemingly more straightforward way uses Get-Team
all teams teams, owners, members and guests in a tenant
<# generateListTeamsWithMembers.ps1
get all teams in a tenant along with each Team's owners, members and guests
Write 2 lists:
1. Team info with associated arrays like owners, members, guests,
channels concatenated for each team
2. Minimal Team info with separate line for each Team member
If you felt ambitious, you could get all owners, guests & channels, too.
#>
$teams
=
Get-Team
| sort DisplayName
$teamsCount
=
$teams.count
# 358
$teamsInfo
=
@()
# one record for each Team
$teamsMemberInfo
=
@()
# record for each member of a Team
$i
=
0
foreach
($team
in
$teams) {
$i++
$displayname
= ($team.DisplayName)
Write-Host
"$i
of
$($teamsCount):
$displayname" -ForegroundColor Green
$groupid
=
$team.groupid
$members
= (Get-TeamUser
-GroupId
$groupid
-Role Member).User
$owners
= (Get-TeamUser
-GroupId
$groupid
-Role Owner).User
$guests
= (Get-TeamUser
-GroupId
$groupid-Role Guest).User
$channels
=
Get-TeamChannel
-GroupId
$groupid
$channelsDisplayNames
=
@()
foreach
($channel
in
$channels) {
$channelsDisplayNames
+=
$channel.DisplayName
}
#
1st custom object to store various properties of the Teams
#
but any properties with arrays (e.g.: members) will be concatenated, separated
by spaces
$teamsInfo
+= [pscustomobject]@{
DisplayName
=
$displayname
OwnerCount
=
$owners.Count
Owner
= ("$owners") # concatenates with spaces so it'll display properly when exporting to CSV
MemberCount
=
$members.Count
Members
= ("$members")
GuestCount
=
$guests.Count
Guests
= ("$guests")
ChannelsCount
=
$channels.Count
channels
=
$channelsDisplayNames
-join
", "
Description
=
$team.Description
Visibility
=
$team.Visibility
MailNickName
=
$team.MailNickName
Archived
=
$team.Archived
ID
=
$groupid}
$j
=
0
foreach
($member
in
$members) {
$j++
# 2nd custom object with separate record for each member for the
Teams
$teamsMemberInfo
+= [
pscustomobject]@{
DisplayName
=
$displayname
ID
=
$groupid
MemberCount
=
"'$displayname':
$j
of
$($members.Count)"
Member
=
$member}
}
#
uncomment below when testing
if
($i
-gt
5) {break}
}
# show these two lists of team information in OutGrid-View
$teamsInfo
| ogv
$teamsMemberInfo
| ogv
$dir
= [environment]::getfolderpath("mydocuments")
# export these two lists of team information to CSV
$docName
=
"$($dir)/teams"
$path="$($docName)_$((Get-Date
-format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
$teamsInfo
| /span>
Sort-Object DisplayName |
Export-Csv
$path
-Encoding UTF8 -NoTypeInformation
$docName
=
"$($dir)/teamsWithMembers"
$path="$($docName)_$((Get-Date-format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
$teamsMemberInfo
|
Sort-Object DisplayName |
Export-Csv
$path
-Encoding UTF8 -NoTypeInformation
Teams search is retarded in that the purported wildcard only works for stuff at the beginning; if the string you're looking for is somewhere in the middle, forget it. The code below works around this.
$match
=
"Tech"
$AzureGroups
=
Get-AzureADmsGroup
-All
100000
|
?
{$_.Grouptypes
-ne
""} | select ID,DisplayName,GroupTypes | Sort DisplayName
foreach
($azGroup
in
$AzureGroups)
{
$DisplayName
=
$azGroup.DisplayName
if
($DisplayName
-match
$match)
{
[pscustomObject]@{
#ID = $azGroup.ID
DisplayName
=
$DisplayName
GroupTypes
=
$azGroup.GroupTypes
}
}
}