Jump to content

Teams - Powershell export user teams (owners and members)


Recommended Posts

Posted

Hi there

 

I'm after making a powershell script that i can enter a user name and it return all teams memberships both owner and members

 

I can get the details using this but i can't export the details as it gives me more data if i use export-csv or out-file, or even out-gridview.

 

as always thanks to anyone that takes the time to have a look.

 



$User = [email][email protected][/email]
$teams=Get-Team -User $User

$teams | ForEach-Object {

   Write-host "Getting details for Team $($_.DisplayName)"

   # Get Owners, members and guests

   $TeamOwnersUsers = Get-TeamUser -GroupId $_.GroupID -Role Owner
   $TeamMembersUsers = Get-TeamUser -GroupId $_.GroupID -Role Member
                   
   $TeamOwnerName = ($TeamOwnersUsers | Where-Object {$_.User -like $User })
   $TeamMembersName = ($TeamMembersUsers | Where-Object {$_.User -like $User })
   # Put all details into an object

   $output = New-Object -TypeName PSobject 

   $output | add-member NoteProperty "DisplayName" -value $_.DisplayName 
   $output | add-member NoteProperty "Description" -value $_.Description
   $output | add-member NoteProperty "Visibility" -value $_.Visibility
   $output | add-member NoteProperty "Archived" -value $_.Archived
   $output | add-member NoteProperty "GroupId" -value $_.GroupId
   $output | add-member NoteProperty "Owner" -value $TeamOwnerName.Name 
   $output | add-member NoteProperty "Member" -value $TeamMembersName.Name 

   $OutputCollection += $output
   }

   # Output collection
   $OutputCollection

Posted

You're not creating the output collection as an array,

 

$OutputCollection=@()

 

At the start. Not exactly sure what you are looking for, but after I did that, it ran and gave me useful stuff.

Posted

Thanks for that. It better now but if a user is a member and an owner its only showing me owner and not both. Any ideas?

 

Thanks

Posted
Thanks for that. It better now but if a user is a member and an owner its only showing me owner and not both. Any ideas?

Thanks

 

If a user is an owner in a team they won't be listed as a member because they can only be one of those roles

Posted

Thanks for that.

 

If i add a user via teams admin centre or teams itself it adds the user as both a member and owner of the team, (So does Locker too)

 

I've noticed if add user Mr.Smith to team Test1 as an owner in Azure directly, when i search for Mr.Smith and look at his groups it doesn't show Test1. If i add Mr.Smith as the owner and the member then the group shows in that way.

 

Hence why i wanted a report to show me who teams a user is the owner and member of.

 

Hope this makes some kind of sense.

Thanks

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...