0
votes

I have a simple Powershell script to create a Microsoft team, channels, users, and then to associate the users with the channels. I'm currently prompting user to enter team name, and then to copy past the GroupID, as I cannot figure out how to get just the group ID. Is there any way I can just get the "GroupID" so I can assign it to a variable and not force the user to copy-paste?

Connect-MicrosoftTeams
$NewTeamName = Read-Host -Prompt 'Name of new Team'
New-Team -DisplayName $NewTeamName
Get-Team -DisplayName $NewTeamName
$GroupId = Read-Host -Prompt 'Copy and past the GroupID above'
Import-csv createTeamChannels.csv | foreach{New-TeamChannel -GroupId $GroupId -DisplayName $_.cname -MembershipType Private}
...
1

1 Answers

1
votes

You can use the member access operator (.) to return only the GroupId property value of an existing Team.

$GroupId = (Get-Team -DisplayName $NewTeamName).GroupId

According to New-Team, the GroupId is output when a Team is created. So you can store the New-Team output in a variable and have access to the property.

Connect-MicrosoftTeams
$NewTeamName = Read-Host -Prompt 'Name of new Team'
$NewTeam = New-Team -DisplayName $NewTeamName
$GroupId = $NewTeam.GroupId