Forum Discussion
DazzaR
Feb 27, 2020Steel Contributor
Powershell question about getting all Team owners so I can email them
If I have all the IDs for my teams in a csv, how do I use something like this to just pull out the owners? Get-TeamUser -GroupId [team ID goes here] -Role Owner Outcome I want is to be able t...
- Feb 27, 2020
If you want to only get owners for some teams that you have in a CSV with a header called GroupID you can to it like this:
$GroupIDs = Import-Csv -Path C:\PathToCSV\Teams.csv foreach($Group in $GroupIDs) { $Owners = Get-Team -GroupId $Group.GroupID | Get-TeamUser -Role Owner foreach ($Owner in $Owners) { Get-AzureADUser -ObjectID $Owner.User | Select Mail } }
But you still need to connect to Azure AD with powershell (only read access) and Teams (only read access).
LinusCansby
Feb 27, 2020MVP
Hi,
If you want E-mail addresses for all Team Owners you could do something like this. You have to connect to Azure AD Powershell and Teams powershell first.
$Users = (Get-Team | Get-TeamUser -Role owner).user
foreach($User in $Users)
{
Get-AzureADUser -ObjectID $User | Select Mail
}
But do you only want the owners for the Teams that you have in the CSV or is this Okay?
- DazzaRFeb 27, 2020Steel Contributor
LinusCansby good question, your suggestion is also useful. Our set up is that Teams admin have Team admin plus SharePoint admin. Very frustrating trying to do anything with the AAD commands because we're missing the exchange role.
Ideally I'd like to loop through a predefined list of Teams IDs.
- LinusCansbyFeb 27, 2020MVP
If you want to only get owners for some teams that you have in a CSV with a header called GroupID you can to it like this:
$GroupIDs = Import-Csv -Path C:\PathToCSV\Teams.csv foreach($Group in $GroupIDs) { $Owners = Get-Team -GroupId $Group.GroupID | Get-TeamUser -Role Owner foreach ($Owner in $Owners) { Get-AzureADUser -ObjectID $Owner.User | Select Mail } }
But you still need to connect to Azure AD with powershell (only read access) and Teams (only read access).