Home

PowerShell New-Team not always working in script (0.9.6)

%3CLINGO-SUB%20id%3D%22lingo-sub-464984%22%20slang%3D%22en-US%22%3EPowerShell%20New-Team%20not%20always%20working%20in%20script%20(0.9.6)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-464984%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20seems%20that%20there%20are%20some%20problems%20with%20stability%20in%20executing%20the%20New-Team%20command%20within%20a%20script.%20I%20haven't%20found%20the%20exact%20pattern%20in%20when%20it%20fails%2C%20but%20I%20have%20experienced%20the%20following%2C%20when%20executing%20the%20New-Team%20command%3A%3C%2FP%3E%3CUL%3E%3CLI%3ENo%20output%20to%20the%20screen%20and%20no%20team%20is%20created%3C%2FLI%3E%3CLI%3EGroupId%20outputted%20to%20screen%2C%20but%20no%20team%20is%20created%3C%2FLI%3E%3CLI%3EGroupId%20outputted%20to%20screen%20and%20team%20is%20created%3C%2FLI%3E%3C%2FUL%3E%3CP%3EI%20have%20tried%20the%20following%20ways%20of%20executing%20the%20New-Team%20command%3A%3C%2FP%3E%3CUL%3E%3CLI%3EFrom%20the%20PowerShell%20shell%20(no%20script)%3CBR%20%2F%3ENew-Team%20-DisplayName%20%24TeamName%20-Description%20%22Test%22%20-AccessType%20Public%3CBR%20%2F%3ESuccessfull%3C%2FLI%3E%3CLI%3EFrom%20a%20simple%20script%20(no%20functions%20or%20foreach%20loops)%3CBR%20%2F%3ENew-Team%20-DisplayName%20%24TeamName%20-Description%20%22Test%22%20-AccessType%20Public%3CBR%20%2F%3EMost%20often%20successfull%2C%20but%20sometimes%20groupId%20is%20returned%2C%20but%20no%20Team%20is%20created%3C%2FLI%3E%3CLI%3EFrom%20a%20script%20within%20a%20foreach%20loop%3CBR%20%2F%3ENew-Team%20-DisplayName%20%24TeamName%20-Description%20%22Test%22%20-AccessType%20Public%3CBR%20%2F%3EMost%20often%20NOT%20successfull%2C%20with%20no%20GroupId%20output%3C%2FLI%3E%3CLI%3EFrom%20a%20script%20within%20a%20foreach%20loop%3CBR%20%2F%3E%24GroupObject%20%3D%20New-Team%20-DisplayName%20%24TeamName%20-Description%20%22Test%22%20-AccessType%20Public%3CBR%20%2F%3EMost%20often%20successfull%2C%20maybe%20all%20the%20time%3C%2FLI%3E%3CLI%3EFrom%20a%20script%20within%20function%2C%20called%20from%20a%20foreach%20loop%3CBR%20%2F%3ENew-Team%20-DisplayName%20%24TeamName%20-Description%20%22Test%22%20-AccessType%20Public%3CBR%20%2F%3ENever%20successfull%3C%2FLI%3E%3CLI%3EFrom%20a%20script%20within%20function%2C%20called%20from%20a%20foreach%20loop%3CBR%20%2F%3E%24GroupObject%20%3D%20New-Team%20-DisplayName%20%24TeamName%20-Description%20%22Test%22%20-AccessType%20Public%3CBR%20%2F%3EMost%20often%20successfull%3C%2FLI%3E%3C%2FUL%3E%3CP%3EAs%20I%20mentioned%2C%20I%20have't%20found%20a%20total%20pattern%20to%20these%20problems%20as%20sometimes%20something%20will%20work%2C%20that%20I%20have%20seen%20fail%20before.%20Although%20it%20seems%20that%20putting%20the%20result%20into%20a%20variable%20(%22%24GroupObject%20%3D%20New-Team...%22)%20makes%20the%20command%20the%20most%20successfull.%3CBR%20%2F%3E%3CBR%20%2F%3EHere%20is%20my%20testing%20script%2C%20where%20I%20have%20experienced%20some%20problems%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24TeamNames%20%3D%20%22TestTeamName46%22%20-split%20'%3B'%3CBR%20%2F%3EWrite-Host%20%22Team%20name%3A%22%20%24TeamNames%5B0%5D%3CBR%20%2F%3EForeach%20(%24TeamName%20in%20%24TeamNames)%3CBR%20%2F%3E%7BNew-Team%20-DisplayName%20%24TeamName%20-Description%20%22Test%22%20-AccessType%20Public%7D%3CBR%20%2F%3EWrite-Host%20%22Waiting%2010%20seconds%20for%20team%20to%20get%20ready%22%3CBR%20%2F%3EStart-Sleep%20-Seconds%2010%3CBR%20%2F%3EIf%20((Get-Team).DisplayName.Contains(%24TeamNames%5B0%5D))%3CBR%20%2F%3E%7BWrite-Host%20%22Team%20was%20found!%22%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EUpdate%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3ESeems%20that%20sometimes%2C%20when%20I%20actually%20get%20the%20GroupID%20returned%2C%20that%20the%20Office%20365%20group%20has%20been%20created%2C%20but%20New-Team%20failed%20at%20creating%20a%20Team%20for%20the%20group.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-464984%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ENew-team%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-482648%22%20slang%3D%22en-US%22%3ERE%3A%20PowerShell%20New-Team%20not%20always%20working%20in%20script%20(0.9.6)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-482648%22%20slang%3D%22en-US%22%3EPlease%20upgrade%20to%20the%20newest%20version%20of%20Powershell.%20THis%20is%20just%20released%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-482654%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20PowerShell%20New-Team%20not%20always%20working%20in%20script%20(0.9.6)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-482654%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1585%22%20target%3D%22_blank%22%3E%40paul%20keijzers%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20the%20heads%20up.%20I%20will%20test%20it%20and%20see%20if%20that%20helps%20with%20the%20issue.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
ahl2ndc
Occasional Contributor

It seems that there are some problems with stability in executing the New-Team command within a script. I haven't found the exact pattern in when it fails, but I have experienced the following, when executing the New-Team command:

  • No output to the screen and no team is created
  • GroupId outputted to screen, but no team is created
  • GroupId outputted to screen and team is created

I have tried the following ways of executing the New-Team command:

  • From the PowerShell shell (no script)
    New-Team -DisplayName $TeamName -Description "Test" -AccessType Public
    Successfull
  • From a simple script (no functions or foreach loops)
    New-Team -DisplayName $TeamName -Description "Test" -AccessType Public
    Most often successfull, but sometimes groupId is returned, but no Team is created
  • From a script within a foreach loop
    New-Team -DisplayName $TeamName -Description "Test" -AccessType Public
    Most often NOT successfull, with no GroupId output
  • From a script within a foreach loop
    $GroupObject = New-Team -DisplayName $TeamName -Description "Test" -AccessType Public
    Most often successfull, maybe all the time
  • From a script within function, called from a foreach loop
    New-Team -DisplayName $TeamName -Description "Test" -AccessType Public
    Never successfull
  • From a script within function, called from a foreach loop
    $GroupObject = New-Team -DisplayName $TeamName -Description "Test" -AccessType Public
    Most often successfull

As I mentioned, I have't found a total pattern to these problems as sometimes something will work, that I have seen fail before. Although it seems that putting the result into a variable ("$GroupObject = New-Team...") makes the command the most successfull.

Here is my testing script, where I have experienced some problems:

 

$TeamNames = "TestTeamName46" -split ';'
Write-Host "Team name:" $TeamNames[0]
Foreach ($TeamName in $TeamNames)
{New-Team -DisplayName $TeamName -Description "Test" -AccessType Public}
Write-Host "Waiting 10 seconds for team to get ready"
Start-Sleep -Seconds 10
If ((Get-Team).DisplayName.Contains($TeamNames[0]))
{Write-Host "Team was found!"}

 

Update:

Seems that sometimes, when I actually get the GroupID returned, that the Office 365 group has been created, but New-Team failed at creating a Team for the group.

2 Replies
Please upgrade to the newest version of Powershell. THis is just released

@paul keijzers 

Thank you for the heads up. I will test it and see if that helps with the issue.

Related Conversations
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
22 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
description for autoplay blocking in settings page
HotCakeX in Discussions on
8 Replies