Jump to content

Recommended Posts

Posted

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

Posted

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

  • Thanks 1
Posted

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 )

  • Thanks 1
Posted
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!
  • Thanks 1
Posted (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 by HPlum78
  • Thanks 1
Posted
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 )

  • Thanks 1
Posted (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 by HPlum78
  • 1 year later...
Posted
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"

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...