Sep 13 2019 08:34 AM - edited Sep 13 2019 08:40 AM
So the history is we had 260 subsites in SharePoint on premises 2010 that we migrated to 260 SPO site collections created sans groups. Next we associated each site collection to a new group using powershell script like so:
$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
}
…. so now if you connect to any of the site url's you'll see a Microsoft Teams Create a Team prompt in lower left corner...
The question, is there a powershell switch to click that button that I can run in a foreach loop?
Also when I associate the SPO site to new MS Teams using gui, the SharePoint owners and members groups are auto added to the group. I'll need a way to automate this in powershell as well.
Thanks for any help!
Regards,
/Robin
Sep 16 2019 04:33 AM - edited Sep 16 2019 04:36 AM
Solution
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 } } }
Sep 16 2019 06:31 AM
Sep 16 2019 04:33 AM - edited Sep 16 2019 04:36 AM
Solution
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 } } }