Jump to content

Powershell import users to various teams (CSV?) (Requesting help)


Recommended Posts

Posted

Hope someone can help me out as I'm hitting brick wall and it doesn't help my powershell knowledge is vary limited;

 

I'm looking to import a list of users to multiple teams, idealy from CSV file (2 sperate list either one CSV or 2 CSV), but I'm getting few issues;

I can't tell the script to read the two lists seperatly (either from 1 CSV File or 2 CSV files), it reads each row as a single line

 

Only ways I can get it working is either add list of users one team at a time by editing the line to specifically state what group ID or using visual basic input box prompting the user to enter in username and then adding that user to list of teams (not bad for one offs etc.)

 

I thought about using a double for each (nesting I think it's called?) but that doesn't work as stated above it reads the row data as a single line, or i can't figure out how tell the script; for this group add the list of users, next group and add the list of users etc.

 

sorry if my explination is confusing, mix of tired and dylexia.

Posted
So you have two CSVs. One with users. The second with the Team ID?

Do you want all of the users to be added to all of the teams listed in the CSV?

 

yes (I do have one CSV with both lists but don't think this would work), but what you said is what I want to do :)

 

I had used this line of code;

Import-Csv -Path C:\TEMP\TEMP\tempTeam.csv | ForEach-Object {Add-TeamUser -GroupId $_.group_id -Role Owner -user USEREMAIL}

For the code that promps me for username etc.

Posted

I realised that before but it complicates things when trying to things on the fly for allot of groups/users, I had one where I was adding heads of years to various form groups per year etc.

 

which is why I wanted to do it where it goes through two list, two CSV is fine to do :)

Posted (edited)

If I understand what your after you should be able to recreate this using your two csv imports but this will pass each user into each group. If you paste your code might be easier to assist with.

 

 

 


$Users = "Eric","Hayley","Miss Take"

$Groups = "Maths","Science","History"


Foreach ($group in $groups) {
foreach ($User in $Users)
{Write-host "Team name is" $group "adding user $User"}}

Edited by tri_94
  • Thanks 1
Posted (edited)
If I understand what your after you should be able to recreate this using your two csv imports but this will pass each user into each group. If you paste your code might be easier to assist with.

 

 

 


$Users = "Eric","Hayley","Miss Take"

$Groups = "Maths","Science","History"


Foreach ($group in $groups) {
foreach ($User in $Users)
{Write-host "Team name is" $group "adding user $User"}}

 

So I tried this with an earlier inporter code (CSV to aray)

 

$Users = Import-Csv -Path "C:\TEMP\New folder (2)\tempUser.csv" | ForEach-Object {$_.user_list}
$Groups = Import-Csv -Path "C:\TEMP\New folder (2)\tempTeam.csv" | ForEach-Object {$_.group_id}


Foreach ($group in $groups) {
foreach ($User in $Users){
Write-host "Add-TeamUser -GroupId $group -Role Owner -user $User"}}

 

and the result;

 

PS C:\WINDOWS\system32>
$Users = Import-Csv -Path "C:\TEMP\New folder (2)\tempUser.csv" | ForEach-Object {$_.user_list}
$Groups = Import-Csv -Path "C:\TEMP\New folder (2)\tempTeam.csv" | ForEach-Object {$_.group_id}

Foreach ($group in $groups) {
foreach ($User in $Users){
Write-host "Add-TeamUser -GroupId $group -Role Owner -user $User"}}

Add-TeamUser -GroupId 00000000-0000-0000-0000-00000000000 -Role Owner -user DPenfold@email
Add-TeamUser -GroupId 00000000-0000-0000-0000-00000000000 -Role Owner -user TestStaff@email

PS C:\WINDOWS\system32>

(obviously changed group ID and email etc.)

 

looks like itswhat I need, I'll test now with out "wrtie-host" :)

Edited by DPenfold
Posted

PS C:\WINDOWS\system32>
$Users = Import-Csv -Path "C:\TEMP\New folder (2)\tempUser.csv" | ForEach-Object {$_.user_list}
$Groups = Import-Csv -Path "C:\TEMP\New folder (2)\tempTeam.csv" | ForEach-Object {$_.group_id}

Foreach ($group in $groups) {
foreach ($User in $Users)
{Add-TeamUser -GroupId $group -Role Owner -user $User}}

 

Works, for each team in Team CSV will add all users from User CSV

 

@DaveTheTech and @tri_94 thank you so much for the help! :D

Posted

Brill glad it worked.

 

Just something incase you're not aware off, We now add users as owner and member otherwise if i search for the user and check thier groups on azure it doesn't seem to show groups that they are only an owner off. Its worth checking on the ones you had just done to see if this is the same for you.

Posted
Brill glad it worked.

 

Just something incase you're not aware off, We now add users as owner and member otherwise if i search for the user and check thier groups on azure it doesn't seem to show groups that they are only an owner off. Its worth checking on the ones you had just done to see if this is the same for you.

 

We've not migrated over to azure yet (still AD), for now staff are added as owners and students as members based on SIM info/timetable, this script witll help add additional staff to groups/teams that couldn't be done with SIM info etc.

 

I will pass this over to the other technicians so we all know when ever we do migrate, thanks! :).

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...