MkII Posted May 12, 2020 Posted May 12, 2020 Hi I have admin staff wanting access to most if not all teams and it's impractical to add them one by one. I have a request to add one person to all Year 10 classes to see what work has been set. (Unless there's another way to do this?) That's 56 classes. I'm sure I'll get more of these requests. Is there a way to do this efficiently? Thanks
mavhc Posted May 12, 2020 Posted May 12, 2020 Powershell. Hopefully your teams have a strict naming system to make it easier. 1
MkII Posted May 12, 2020 Author Posted May 12, 2020 Hopefully your teams have a strict naming system to make it easier. Haha!
psydii Posted May 12, 2020 Posted May 12, 2020 Something like the following pseudo code should do it $t =get-team export-csv $t -path c:\teamlists.csv use excel to edit the csv to just the teams you want to change $t1 = import-csv -path youreditedfile foreach $team in $t1 add-teamuser team.GroupID -user upn I'm not completely sure get-team does work that way, so you might need to use get-unifiedgroup instead and use the ExternalDirectoryObjectID as the source of the GroupID you use in the add-teamuser command 1
2097 Posted May 13, 2020 Posted May 13, 2020 Script 1 Import-Module ActiveDirectory $When = ((Get-Date).AddDays(-9999)).Date $Staff = 'C:\Scripts\Teams\CSV\Staff.csv' Get-ADGroupMember -Identity "Admin Staff" | Get-ADUser -Properties whenCreated | Select-Object UserPrincipalName| Export-Csv -Path $Staff –notypeinformation Script 2 Connect-MicrosoftTeams Import-Csv -Path "C:\Scripts\Teams\CSV\Staff.csv" | foreach{Add-TeamUser -GroupId GOUPIDNUMBER -user $_.UserPrincipalName} Change "Admin Staff" to AD group of your "Admin Staff" 2nd Script , Line 2 adds users exported from AD Admin staff into each Group you specify , add multiple lines for more groups ( you will need the group ID numbers ) 1
HPlum78 Posted May 13, 2020 Posted May 13, 2020 If your teams don't have a coherent naming convention and it's all year 10 groups do you have a group that is already unique assigned to those year 10 groups? If so then we should be able to find the teams with a script. If not then you are going to have to try and find something that you can identify them by or its a hand ball job! 1
HPlum78 Posted May 13, 2020 Posted May 13, 2020 (edited) @mavhc it's always useful to know the date that is 9999 days in the past, its recommended that you find that date in all the scripts you run. We are all doing these days get with the program son! :-p Edited May 13, 2020 by HPlum78 1
2097 Posted May 14, 2020 Posted May 14, 2020 What's the $When for? Used it for the initial run to make sure all the staff get added ( im sure none have been there longer than 9999 days ) I then run it every 2 days (-2) to add new people who come into school ( i run these as a scheduled task to stop me having to do it manually ) 1
HPlum78 Posted May 14, 2020 Posted May 14, 2020 @2097 what @mavhc is saying is that in the code posted you are not actually doing anything with the $when var!
HPlum78 Posted May 14, 2020 Posted May 14, 2020 (edited) Just on that if you declare a variable in the ISE you get no warning/ notification that you have not used it anywhere in your code, if you use VS Code then you do get that sort of information. Edited May 14, 2020 by HPlum78
2097 Posted March 29, 2022 Posted March 29, 2022 Fantastic! Thanks guys. Found this post again , Looks like i missed some code. I Couldnt figure out howto add only new users from AD Groups . A lot easier if its in a OU . Worked this one out after a few days. This will populate a single CSV with only users added to the system on the specified timing ( the past 2 days )of a specific AD group Import-Module ActiveDirectory $Staff = 'D:\CSV\Test\staff.csv' Get-ADGroupMember -Identity "Staff" | Get-ADUser -Properties WhenCreated | Select-Object UserPrincipalName,whenCreated | Export-Csv -Path $Staff –notypeinformation $Data = Import-CSV "D:\CSV\Test\staff.csv" -Header "UserPrincipalName","whenCreated" $CutoffDate = (Get-Date).AddDays(-2) $Data | Where-Object {$_.whenCreated -as [datetime] -gt $CutoffDate} | Export-Csv -Path "D:\CSV\Test\staffDone.csv" -NoTypeInformation Remove-Item "D:\CSV\Test\staff.csv" Rename-Item -Path "D:\CSV\Test\staffDone.csv" -NewName "Staff.csv"
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now