Forum Discussion
newboerg83
Jun 30, 2021Copper Contributor
powershell new-team does not return object in time
Hello, i am having a problem using powershell to add new Teams. let me show you some example code:
foreach($item in $list){
#some stuff happens above thats working...
if ($autoteam -eq $null){
continue
}
$teamid = Get-team -DisplayName $autoteam
if ($teamid -eq $null){
$teamid = new-team -displayname $autoteam -owner "john.doe@contoso.com" -template "EDU_Class" |out-null
}
#this is my workaround
while ($teamid -eq $null){
sleep -Seconds 3
$teamid = Get-team -DisplayName $autoteam
}
add-teamuser -groupid $teamid.groupid -user $upn |out-null
}
The Problem i cannot wrap my head around is as follows: when i use "new-team" in an interactive PS-Session it returns the groupid as it should (checked the manual).
When using it inside my script it returns nothing.
i found a workaround in which i let the script wait some time, and after aprox. 3-5 seconds the team is created and get-team returns what it should.
It seems to me that the new-team cmdlet only waits till finished when in interactive shell, could that be the problem? and if so, how do you guys do this?
- Hello, Isn't the out-null causing that?
- Hello, Isn't the out-null causing that?
- newboerg83Copper Contributor