Skip to content

Instantly share code, notes, and snippets.


dannneal/AutoAddTeams.ps1 Secret

Created Jan 3, 2021
What would you like to do?
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 $}
#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