Jump to content

Recommended Posts

Posted

Hi there

 

I've made a script that from csv will add users to teams and I'm trying to record the users added to which team. Currently it tells me on screen.

 

However i've tried but can't seem to get it working.

 

any help would be great.

 

Thanks

 

$data = Import-csv "D:\test\Teamsuser2.csv" 


foreach ($i in $data) {
Add-TeamUser -GroupId $i.id -User $i.user  -Role Member 
Write-host $i.User "added to team" $i.displayname "as Member" -ForegroundColor Yellow


Add-TeamUser -GroupId $i.id -User $i.user  -Role Owner 
Write-host $i.User "added to team" $i.displayname "as Owner" -ForegroundColor Green


} 

Posted

Not really sure what your question is, Is it not working as in not adding them? Not showing on screen? Are you trying to record it to a file etc?

 

Steve

Posted (edited)

Are you trying to record it to a file etc? - Yes

 

 

i was trying to use the likes of

 

$output @()

 

and then in the loop $ouput += to add the data to the output variable

 

currently on screen i see

 

"username" is added to team "A" as a member

 

it loops through the csv which at the moment has 20 users and 50 teams

I would just like to export this data so I check back to see if a user was added to a team

 

Does that makes sense

 

Thanks

Edited by tri_94
Posted

So something like

 


$data = Import-csv "C:\test\Teamsuser2.csv" 
$output = @()

foreach ($i in $data) {
Add-TeamUser -GroupId $i.id -User $i.user  -Role Member 
Write-host $i.User "added to team" $i.displayname "as Member" -ForegroundColor Yellow
$output += $i.User + " added to team " + $i.displayname + " as Member"

Add-TeamUser -GroupId $i.id -User $i.user  -Role Owner 
Write-host $i.User "added to team" $i.displayname "as Owner" -ForegroundColor Green
$output += $i.User + " added to team " + $i.displayname + " as Owner"

}

$output | Out-File -Append c:\test\output.txt

 

Which would output a file:

 

test1 added to team test1d as Member

test1 added to team test1d as Owner

test2 added to team test2d as Member

test2 added to team test2d as Owner

 

Like that?

 

Steve

  • Thanks 1
Posted

That's just what i wanted.

 

I had already tried $output += $i.User " added to team " $i.displayname " as Owner" but as you can guess it just errored at me, as I missed the +'s

 

 

Thanks for your help

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