1
votes

I'm trying to automate the creation of a new Microsoft Teams team through Powershell. I'm quite far and the script I made creates a new team and the channels, the only problem I have is that every time I run the script I get this error, which is kind of logical, but I can't fix it. Can anybody help me?

New-Team : Cannot validate argument on parameter 'DisplayName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At C:\Users\Microsoft Teams\NewTeamV2.ps1:10 char:39
+     $GroupID = (New-Team -DisplayName $d.TeamDisplayName -Template $d ...
+                                       ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-Team], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.TeamsCmdlets.PowerShell.Custom.NewTeam

I'm using a loop to go through the CSV file:

CSV File

#Connection
$cred = Get-StoredCredential -Target 'Teams'
Connect-MicrosoftTeams -Credential $cred

#Importeren of data
$data = Import-csv comma.csv

#Loop for creation of teams and channels
foreach ($d in $data) {
    $GroupID = (New-Team -DisplayName $d.TeamDisplayName -Template $d.Template).GroupID
    New-TeamChannel -GroupId $GroupID -DisplayName $d.ChannelDisplayName    
}
1
Yes, i want multiple channels for the same team - pro10boi96

1 Answers

2
votes

Call New-Team only for those rows where the team name is set. For the following rows, the $groupID stays unchanged, so New-TeamChannel will assign the channel to the same team as the previous one.

Let me know if this works for you

foreach ($d in $data) {
    if ($d.TeamDisplayName) {
        $GroupID = (New-Team -DisplayName $d.TeamDisplayName -Template $d.Template).GroupID
    }
    New-TeamChannel -GroupId $GroupID -DisplayName $d.ChannelDisplayName    
}