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 to email them all with a message about a change to the service.
If it's not obvious, I'm not a powershell guy. This is also helping me plug a gap in a far more technical challenge of reporting on connected apps without having to master the Graph API or buy a tool to do it. I'm keeping it low-tech, I'm going to ask people!
Thanks, Darrel
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).
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?
- DazzaRSteel 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.
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).