Forum Discussion
Tien Ngo Thanh
Oct 27, 2019Iron Contributor
add/remove dynamic member in microsoft teams
Hi How to write powershell to add/remove member in microsoft teams . I want add all user in OU to microsoft teams and also remove member if they not in this OU , please anyone guide help me Be...
Tien Ngo Thanh
Nov 01, 2019Iron Contributor
hi
I try add member but after done add member then microsoft teams update member but when access sharepoint site then see new member .Microsoft teams not update member i try logout and login Microsoft teams again but still not see
Best Regards,
VasilMichev
Nov 01, 2019MVP
You'll have to wait for the membership changes to be synchronized across all workloads.
- Tien Ngo ThanhNov 03, 2019Iron Contributor
I would like share my script just finish
thanks you VasilMichev help me
############## Add/Remove Member team base on AD Group ##############
$RootPath = "C:\ScriptsTest\AddRemoveMemberTeam"
$GroupName = "TestTeam-Group"
$TeamName = "Test-Calendar"$Logfile = "$RootPath\outputlogs.csv"
Clear-Content $Logfile
############## Export Member AD Group to csv ############
Get-ADGroupMember -identity $GroupName | select @{name="UserPrincipalName";expression={$_.SamAccountName + "@test.com"}} | Export-csv -path $RootPath\Groupmembers.csv -NoTypeInformation##############connect office365 ############
$NoTimeOut = New-PSSessionOption –IdleTimeout 3600000
$Username = "user@test.onmicrosoft.com"
$Password = ConvertTo-SecureString -AsPlainText "passwordpasthere" -Force$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $Username,$Password
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic –AllowRedirection –SessionOption $NoTimeOut
Import-PSSession $session############## Add/Remove ############
$TeamUsers = Get-UnifiedGroupLinks -Identity $TeamName -LinkType member
$GroupUsers = Import-Csv .\Groupmembers.csv############## Add User from Group AD that no has member in Team ############
foreach($user in $GroupUsers)
{
if ($TeamUsers.WindowsLiveID -notcontains $user.UserPrincipalName)
{
Write-Host "Adding user " $user.UserPrincipalName -ForeGroundColor blue
Add-UnifiedGroupLinks -Identity $TeamName -LinkType member -Links $user.UserPrincipalName -Confirm:$false
$wrapper = New-Object PSObject -Property @{ Action='AddMember'; Username= $user.UserPrincipalName ; Group = $TeamName}
Export-Csv -InputObject $wrapper -Append -Force -Path $Logfile -NoTypeInformation
}
}############## Remove User from Team that no has member in Group AD ############
foreach($user1 in $TeamUsers)
{
if ($GroupUsers.UserPrincipalName -notcontains $user1.WindowsLiveID)
{
Write-Host "Removing user " $user1.WindowsLiveID -ForeGroundColor Red
Remove-UnifiedGroupLinks -Identity $TeamName -LinkType member -Links $user1.WindowsLiveID -Confirm:$false$wrapper = New-Object PSObject -Property @{ Action='RemoveMember'; Username= $user1.WindowsLiveID ; Group = $TeamName}
Export-Csv -InputObject $wrapper -Append -Force -Path $Logfile -NoTypeInformation
}
}
Remove-PSSession $Session- VasilMichevNov 03, 2019MVP
So the users did appear in the SPO membership as well, right?
- Tien Ngo ThanhNov 05, 2019Iron Contributor
VasilMichev yes , after running scripts it have in SPO , but team need time to appear