Forum Discussion
looking for powershell script to "create a team"
- Sep 16, 2019
There is no switch to enable Teams while enabling group to the site. But you can use Teams Powershell command (New-Team) to create team from existing Office 365 group.
Run the below commands to install and connect Teams powershell module :
Install-Module MicrosoftTeams -Force Connect-MicrosoftTeams
The below command gets GroupId from the Site object and creates team for the group.
$SiteObj = Get-SPOSite -Identity $SiteURL.SiteURL New-Team -GroupId $SiteObj.GroupId.Guid
To copy SharePoint group members to Office 365 group. First you can get SPO group members using the Get-SPOSiteGroup cmdlet and add them to Teams group using the Add-TeamUser cmdlet.
I have modified your script :
$sitelist = Import-Csv C:\Users\sp_farmadmin\Documents\modurllist.csv $Cred = Get-Credential Connect-SPOService -Url "https://obfuscatedtenantname-admin.sharepoint.com "-Credential $Cred foreach ($SiteURL in $sitelist) { Set-SPOSiteOffice365Group -Site $SiteURL.SiteURL -DisplayName $GroupDisplayName.GroupDisplayName -Alias $GroupDisplayName.GroupDisplayName #Enable Team $SiteObj = Get-SPOSite -Identity $SiteURL.SiteURL New-Team -GroupId $SiteObj.GroupId.Guid #Copy SharePoint Group Members to Team Members $memberObj = (Get-SPOSiteGroup -Site $SiteURL.SiteURL | Where-Object {$_.Title -like '*Members*'} | Select-Object Users) foreach ($UserId in $memberObj.Users) { #Filter only users, avoid groups and system object #if($UserId -like "*yourdomain.com") { Add-TeamUser -GroupId $SiteObj.GroupId.Guid -User $UserId } } #Copy SharePoint Group Owners to Team Owners $ownerObj = (Get-SPOSiteGroup -Site $SiteURL.SiteURL | Where-Object {$_.Title -like '*Owner*'} | Select-Object Users) foreach ($UserId in $ownerObj.Users) { #Filter only users, avoid groups and system object #if($UserId -like "*yourdomain.com") { Add-TeamUser -GroupId $SiteObj.GroupId.Guid -User $UserId -Role Owner } } }
There is no switch to enable Teams while enabling group to the site. But you can use Teams Powershell command (New-Team) to create team from existing Office 365 group.
Run the below commands to install and connect Teams powershell module :
Install-Module MicrosoftTeams -Force Connect-MicrosoftTeams
The below command gets GroupId from the Site object and creates team for the group.
$SiteObj = Get-SPOSite -Identity $SiteURL.SiteURL New-Team -GroupId $SiteObj.GroupId.Guid
To copy SharePoint group members to Office 365 group. First you can get SPO group members using the Get-SPOSiteGroup cmdlet and add them to Teams group using the Add-TeamUser cmdlet.
I have modified your script :
$sitelist = Import-Csv C:\Users\sp_farmadmin\Documents\modurllist.csv
$Cred = Get-Credential
Connect-SPOService -Url "https://obfuscatedtenantname-admin.sharepoint.com "-Credential $Cred
foreach ($SiteURL in $sitelist)
{
Set-SPOSiteOffice365Group -Site $SiteURL.SiteURL -DisplayName $GroupDisplayName.GroupDisplayName -Alias $GroupDisplayName.GroupDisplayName
#Enable Team
$SiteObj = Get-SPOSite -Identity $SiteURL.SiteURL
New-Team -GroupId $SiteObj.GroupId.Guid
#Copy SharePoint Group Members to Team Members
$memberObj = (Get-SPOSiteGroup -Site $SiteURL.SiteURL | Where-Object {$_.Title -like '*Members*'} | Select-Object Users)
foreach ($UserId in $memberObj.Users)
{
#Filter only users, avoid groups and system object
#if($UserId -like "*yourdomain.com")
{
Add-TeamUser -GroupId $SiteObj.GroupId.Guid -User $UserId
}
}
#Copy SharePoint Group Owners to Team Owners
$ownerObj = (Get-SPOSiteGroup -Site $SiteURL.SiteURL | Where-Object {$_.Title -like '*Owner*'} | Select-Object Users)
foreach ($UserId in $ownerObj.Users)
{
#Filter only users, avoid groups and system object
#if($UserId -like "*yourdomain.com")
{
Add-TeamUser -GroupId $SiteObj.GroupId.Guid -User $UserId -Role Owner
}
}
}
- RobinOrgHoodSep 16, 2019Copper Contributor