Skip to content

Instantly share code, notes, and snippets.

@dannneal
Created January 3, 2021 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannneal/9dbbe9dc87b441972c91bb71663e1cdc to your computer and use it in GitHub Desktop.
Save dannneal/9dbbe9dc87b441972c91bb71663e1cdc to your computer and use it in GitHub Desktop.
Connect-MicrosoftTeams
Get-Team -displayname "YourTeamName"
while($true) {
#Get Teams users, the one's that haven't left...
Get-TeamUser -GroupId (groupidhere) | Select-Object user | out-file C:\PreAddUsers.txt
$PreAddUsers = get-content C:\PreAddUsers.txt
#import the list of users who should be in the Team, add them
import-csv -path "C:\Thisisthelistofusers.csv" | ForEach-Object {Add-TeamUser -groupid (groupidhere) -User $_.email}
#Now, get the list of users in the Teams, for comparing.
Get-Teamuser -GroupId (groupidhere) | Select-Object user | Out-File C:\PostAddUsers.txt
$PostAddUsers = get-content C:\PostAddUsers.txt
#Compares the two lists for outputting
Compare-object -ReferenceObject $PreAddUsers -DifferenceObject $PostAddUsers -PassThru | Out-file C:\UserDiff.txt
$output = Get-Content -path C:\UserDiff.txt -raw
#writes the lists of users who were added back to the Team, along with the date. Then will wait for 6 hours before running again.
Write-host "$output" -ForegroundColor yellow
write-host (get-date).ToString('T') -ForegroundColor green
"Users added were $output"
start-sleep -seconds 23200
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment