Everette Lamb
Everette Lamb

Reputation: 23

Microsoft Teams Team creation automation via CVS file

Now the issue I'm having is with the Microsoft-Teams module new-team -displayname $teamname not recognizing my variable.

$teamname = Import-csv "C:\reports\teamscsv.csv" 
 | select -expand Team_Name
$owner = Import-csv "C:\reports\teamscsv.csv" 
 | select -expand Team_Owner
$team_descr = Import-csv "C:\reports\teamscsv.csv" 
 | select -expand Team_Description New-Team -displayname $teamname -description $team_descr    

Error:

New-Team : Cannot convert System.Object[] to the type System.String required by parameter DisplayName. Specified method is not supported.

$group = get-team
 | where {$_.DisplayName -like "$line.Team_Name"}
 | select -expand GroupID Add-TeamUser -GroupId $group -user $owner -role Owner
                                                                                                                                                                                           Error: 

Add-TeamUser: Cannot bind argument to parameter GroupId because it is null.

Upvotes: 1

Views: 673

Answers (1)

Arun-MSFT
Arun-MSFT

Reputation: 154

We need to send team name as string, here is how we can do it using for loop.

$testcsv = import-csv D:\Microsoft\test.csv

 foreach($test in $testcsv)
 {
    $teamname = $test.Team_Name

    $owner =  $test.Team_Owner
    $team_descr =  $test.Team_Description  

    $group = New-Team -displayname $teamname -description $team_descr -AccessType "private"
    Write-Host ("My team name is: " + $teamname)
 }

Upvotes: 1

Related Questions