pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
988 stars 665 forks source link

Add-Office365GroupToSite returns error when used at the Site Collection level #2163

Open veronicageek opened 5 years ago

veronicageek commented 5 years ago

Reporting an Issue or Missing Feature

Reporting an issue

Expected behavior

I expect the cmdlet to create an O365 Group for my Site Collection.

Actual behavior

Running the cmdlet on a Site Collection URL (which is how it should be used) returns the error Add-PnPOffice365GroupToSite : You can only perform this operation on site collections

Add-O365GroupToSite_Error

Steps to reproduce behavior

Create a (modern) Site Collection not connected to an Office 365 Group from the (new) SPO Admin Center and running the cmdlet.

TeamSite

Which version of the PnP-PowerShell Cmdlets are you using?

What is the version of the Cmdlet module you are running?

Version 3.11.1907.0

How did you install the PnP-PowerShell Cmdlets?

ghost commented 5 years ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

gautamdsheth commented 5 years ago

That's interesting, i tried the exact same scenario and it works for me. I also created the site using PowerShell and then executed the command again and it worked again:

New-PnPTenantSite `
  -Title "Modern Site" `
  -Url "https://tenant.sharepoint.com/sites/test16Jul101" `
  -Description "Modern Site" `
  -Owner "gautam@tenant.onmicrosoft.com" `
  -Lcid 1033 `
  -Template "STS#3" `
  -TimeZone 10 `
  -Wait

Can you try it in another tenant and also try using PowerShell to create the Groupless site ?

veronicageek commented 5 years ago

OK I'll try this week and feedback. Thanks @gautamdsheth

veronicageek commented 5 years ago

After testing on another tenant, it's no better. I've created the site with PowerShell, but got different errors now. It complains about the owners , then when I change the owners it complains about the alias (although this alias doesn't exist at all when using Add-PnPOffice365GroupToSite.

image

gautamdsheth commented 5 years ago

Two things

1) When specifying the owners, don't put the user email of the person executing the script. SharePoint will automatically add that for you. That's why you got the object reference error

2) When you ran the code again, it failed because in the previous step, the group was created. It was most likely not associated with SP Site.

So, can you try it as below:

New-PnPTenantSite -Title TestSite -Url https://tenant.sharepoint.com/sites/TestSite -Owner "admin@tenant.onmicrosoft.com" -Template "STS#3" -TimeZone 2 -Lcid 1033

And then

Add-PnPOffice365GroupToSite -Url "https://tenant.sharepoint.com/sites/TestSite " -Alias "TestNewGroup" -DisplayName "My finance team site group" -Owners "anotheruser@tenant.onmicrosoft.com"

veronicageek commented 5 years ago

That worked thanks @gautamdsheth 👍

veronicageek commented 5 years ago

@gautamdsheth - Coming back after further testing, it seems this only works when the site is created via PowerShell. I get the error Add-PnPOffice365GroupToSite : You can only perform this operation on site collections again if the site is created via the UI...

arnieraju commented 4 years ago

@veronicageek is there any chance you remember which site template you were using when you created the site via the UI?

veronicageek commented 4 years ago

@arnieraju - The Team site with no O365 Group

devinprejean commented 4 years ago

Just trying this Microsoft script out now that does all this groupifying stuff using this cmdlet. I get the same problems as @veronicageek and I am surprised to see such recent traffic on this. I'm using PNP Powershell cmdlets 3.13.1909.0

alexc-MSFT commented 4 years ago

I have the same issue 😥 the frustrating thing is, the sites are created through a Logic App in my solution and I want to keep it that way. I don't want to create them in PowerShell specifically to get around this.

Also not being able to do it at the Site Collection level means the user running this cmdlet needs to be a SharePoint admin, as far as I can tell?

And I want to be able to do this under the context of a regular user who is a Site Collection admin and NOT a SharePoint admin in the tenant.

jonthenerd commented 4 years ago

I've reproduced this without PnP in the mix using straight SharePoint CSOM. What I've found is that the supplied site collection URL is case-sensitive. Those of you seeing this, navigate to the site from Tenant Admin and grab the URL that way, then supply it to your script. I'm going to file a case with Microsoft shortly to see if this can be addressed.

jonthenerd commented 4 years ago

I've now got an open ticket with Microsoft on this. They've reproduced it with the latest CSOM. My workaround of using the case-sensitive URL has functioned so far.

veronicageek commented 4 years ago

Thanks for the update @jonthenerd

jonthenerd commented 4 years ago

Update Microsoft has released a fix for this. If the build of the SharePoint Online server you are hitting is greater than 16.0.20210.12000 you should be set. This can be checked by appending this to your site url: _vti_pvt/buildversion.cnf . I confirmed that the bug is no longer present using CSOM with my developer tenant. As the PnP PowerShell also uses that same CSOM call, it should also be fixed. I don't have time to test that at the moment, so if someone else can confirm then this issue can likely be closed.

robgarrett commented 4 years ago

Latest version of PnP and build: 16.0.20405.12005 - still not working for me :(