I have the following code but unfortunately I am stuck with the -user parameter for remove-azureaduser, it comes back as resource does not exist, any powershell expert willing to help?
Edit: The idea here was that it would work with multiple teams names as well
Connect-MicrosoftTeams
$Teams = Get-Team -DisplayName "test"
$users = Get-TeamUser -GroupId $Teams.GroupId -Role Member | Select-Object user
Foreach ($user in $users) {
Remove-TeamUser -GroupId $Teams.GroupId -User $user
}
2
Answers
After a small adjustmend, the answer is, thanks to Tony:
Docu: https://learn.microsoft.com/en-us/powershell/module/teams/remove-teamuser?view=teams-ps
As I dont have this cmdlets I can’t really verify but I think this is wrong:
Select-Object user? Think this does not work, based on the documentation u need to provide the userPrincipalName to the cmdlet Remove-TeamUser and I don’t think the object returned by the Get-teamUser cmdlet has a property called user.
Simply do this:
I don’t know if the attribute is called userPrincipalName or UPN… just output one user ($user[0]) to see the list of available attributes.