powershell icon indicating copy to clipboard operation
powershell copied to clipboard

Reopening - [BUG] New-PnPSite not working with HubSiteID > Unauthorized

Open NoralK opened this issue 1 year ago • 5 comments

Reporting an Issue or Missing Feature

Reopening #3594

I'm unable to run New-PnpSite when providing a -hubSiteID. When I run it without providing the -HubSiteID, it works. I have the SharePoint Admin role active and in the SharePoint admin center I can perform this action.

More information - GCC Tenant - The hub does not require authorization, as the SharePoint Admin I have created and am a admin over all site collections.

Expected behavior

Create a site with a hub association during creation.

Actual behavior

Line |
  32 |  New-PnPSite -Url "https://orgname.sharepoint.com/sites/testTeam" `
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | {"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":"Attempted to perform an unauthorized
     | operation."}}

Steps to reproduce behavior

Import-Module -Name PnP.PowerShell
Connect-PnPOnline https://orgname-admin.sharepoint.com/ -Interactive

$hub = Get-PnPHubSite -Identity "https://orgname.sharepoint.com/sites/IT"

New-PnPSite -Url "https://orgname.sharepoint.com/sites/testTeam" `
    -Type TeamSiteWithoutMicrosoft365Group `
    -Title "Test Team Site" `
    -Description "Test Team Site Description" `
    -Owner "[email protected]" `
    -HubSiteId $hub.SiteId #00000000-0000-0000-0000-000000000000 FYI GUID is scrubbed

I performed the suggestion by @gautamdsheth to use the GUID to create the site, this did not work. As mentioned by OP and now me, running Add-PnPHubSiteAssociation after the site creation succeeds.

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

In PS-ISE - v1.12.0 In vsCode and PowerShell v7.4.1 - v2.3.0

Which operating system/environment are you running PnP PowerShell on?

  • [ X ] Windows
  • [ ] Linux
  • [ ] MacOS
  • [ ] Azure Cloud Shell
  • [ ] Azure Functions
  • [ ] Other : please specify

NoralK avatar Feb 28 '24 21:02 NoralK

@veronicageek - can you also try and reproduce this issue ? I couldn't , so not sure if we can do anything about this. For me, it works everytime.

gautamdsheth avatar Feb 29 '24 14:02 gautamdsheth

@gautamdsheth @veronicageek - Could it be due to our Tenant being a GCC?

NoralK avatar Feb 29 '24 16:02 NoralK

No idea, can you maybe try setting the owner parameter the same as the one you use to connect to and try again ?

gautamdsheth avatar Mar 01 '24 10:03 gautamdsheth

My bad, I need to update to original code. I specified the owner being an email address when in fact it is an Azure AD Group.

New-PnPSite -Url "https://orgname.sharepoint.com/sites/testTeam" `
    -Type TeamSiteWithoutMicrosoft365Group `
    -Title "Test Team Site" `
    -Description "Test Team Site Description" `
    -Owner "<<AzureAD Group Display Name>>" `
    -HubSiteId $hub.SiteId #00000000-0000-0000-0000-000000000000 FYI GUID is scrubbed

Therefore the (Get-PnPSite).Owner is blank. I looked at the documenation again, New-PnPSite ... (parms) ... -Owner ... If this parameter is skipped or a group object is provided, the user running New-PnPSite command will be set as a site owner., this is not happening, again it is blank.

NoralK avatar Mar 03 '24 03:03 NoralK

@gautamdsheth @veronicageek any updates?

NoralK avatar Mar 05 '24 17:03 NoralK

No updates and we can't repro it either, will move it to discussion forum in case someone in the community has idea.

gautamdsheth avatar Mar 19 '24 22:03 gautamdsheth