Forum Discussion

JFM_12's avatar
JFM_12
Iron Contributor
Aug 06, 2024

Script to get a list of all Owners from TeamsID-List

Hello

 

I do have a script that imports a csv with Teams ID's and returns me a CSV with TeamsID, Owner-UPN and Owner-Name

 

 

$groups= Get-Content -Path "Paht\Reports_AllTeamsApps_ID - Copy.csv"
#$teamColl=Get-Team
$teamColl=Get-Team -GroupID $groups
# Loop through the teams  
foreach($team in $teamColl)  
{  
    # Get the team owners  
    Get-TeamUser -GroupId $team -Role Owner | Select-Object $team.GroupId,$owner.UserId,$owner.User | export-csv -encoding unicode -NoTypeInformation -path E:\ConnectCyberARK\Juan\Repository\Components\Report_Components_Owners.csv -append  
} 

 

 

I do get following error

 

Get-TeamUser : Error occurred while executing
Code: Request_BadRequest
Message: Invalid object identifier 'Microsoft.Teams.PowerShell.TeamsCmdlets.Model.TeamSettings'.
InnerError:
RequestId: 30e1efd1-c74c-441f-b517-acd88e72a052
DateTimeStamp: 2024-08-06T11:24:08
HttpStatusCode: Request_BadRequest
At line:11 char:5
+ Get-TeamUser -GroupId $team -Role Owner | Select-Object $team.Gro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-TeamUser], ApiException
+ FullyQualifiedErrorId : Microsoft.Teams.PowerShell.TeamsCmdlets.ErrorHandling.ApiException,Microsoft.Teams.PowerShell.TeamsCmdlets.GetTeamUser

 

I have tried to run this

# Get all the teams from tenant 
$groups= Get-Content -Path "Path\Reports_AllTeamsApps_ID - Copy.csv"
$teamColl=Get-Team -GroupID $groups
 # Loop through the teams 
foreach($team in $teamColl) 
{
    # Get the team owners 
    $ownerColl= Get-TeamUser -GroupId $team.GroupId -Role Owner 
    #Loop through the owners 
    foreach($owner in $ownerColl) 
    { 
        Write-Host -ForegroundColor Yellow "User ID: " $owner.UserId "   User: " $owner.User  "   Name: " $owner.Name "Teams ID: " $team.GroupId
    }     
}

But do get following error

 

Get-Team : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'GroupId'. Specified method is not supported.
At line:4 char:29
+ $teamColl=Get-Team -GroupID $groups
+ ~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Team], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Teams.PowerShell.TeamsCmdlets.GetTeam

 

Do you have a hint

Regards

 

JFM_12
 

    • JFM_12's avatar
      JFM_12
      Iron Contributor

      Sayali-MSFT 

      Hello

      Thank you.
      I was able to resolve it using another script.

      Thank you again

      Take care

      JFM_12

Resources