1

Cross-posted at https://stackoverflow.com/questions/61315818/error-with-powershell-pnp-command-for-new-pnp-site

Running the Windows PowerShell ISE as administrator with Import-Module SharePointPnPPowerShellOnline -verbose.

I'm connected to the SharePoint online site. Using get-pnptenantsite works fine.

I issue the following command:

New-PnPSite -Type TeamSite -Title "Aaa aaa" -Alias "aaaa" -Owners "[email protected],[email protected]" -Lcid 5129

It sits for ten minutes, then comes back with the error.

New-PnPSite : OfficeDevPnP.Core.Sites.SiteCollection.CreateAsync: Could not create team site.
At line:1 char:1
+ New-PnPSite -Type TeamSite -Title "Aaa aaa" -Alias "aaaa" -Owners "me ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [New-PnPSite], Exception
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.NewSite

I try with fewer owners and no Lcid.

New-PnPSite -Type TeamSite -Title "Aaa aaa" -Alias "aaaa" -Owners "[email protected]"

It immediately comes back with the error that the group alias exists:

New-PnPSite : {"error":{"code":"-2147024713, Microsoft.SharePoint.SPException","message":"The group alias already exists."}}
At line:1 char:1
+ New-PnPSite -Type TeamSite -Title "Aaa aaa" -Alias "aaaa" -Owners "me ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [New-PnPSite], Exception
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.NewSite

Why does that alias exist? It just told me it couldn't create it.

So I try again with a different alias:

New-PnPSite -Type TeamSite -Title "BBB aaa" -Alias "bbbb" -Owners "[email protected]"

Now I get the error

New-PnPSite : {"error":{"code":"-1, System.Data.Services.Client.DataServiceClientException","message":"{\"odata.error\":{\"code\":\"Request_BadRequest\",\"me
ssage\":{\"lang\":\"en\",\"value\":\"One or more added object references already exist for the following modified properties: 'owners'.\"}}}"}}
At line:1 char:1
+ New-PnPSite -Type TeamSite -Title "BBB aaa" -Alias "bbbb" -Owners "me ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [New-PnPSite], Exception
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.NewSite

What am I doing wrong? Will it be faster to create two dozen sites manually through the admin center?

2 Answers 2

2

The -Lcid 5129 parameter causes the site creation to fail.

Removing that parameter and also reducing the Owners parameter to have only additional owners worked.

The documentation about the Owners parameter is misleading, because it does not say anything about NOT including the account running the script.

2

There are multiple things going on here.

First run
The New-PnPSite command was waiting for the site to be reported as provisioned (all assets and artifacts fully provisioned by SharePoint, this takes a while!) and ended up timing out. The site had in fact been created in just a few seconds, which is why it fails the next time.

Solution
The New-PnPSite should according to the documentation only wait for the site to be provisioned if the -Wait switch is set. However it seems to do that anyways, unless you explicitly set it to $false like so:

New-PnPSite -Type TeamSite -Alias "TEST" -Title "TEST" -Wait:$false

Second run
As mentioned above, this was due to the site and Office 365 Group alias already existing.

Third run
This time the problem was with the -Owners flag. You are specifying your own account - which if nothing else is specified in the -Owners parameter will be added by default as the only owner.
If you add it here, it will already have been added and it throws an error.

Solution
If you only want your own user to be the owner, drop this parameter. If you want multiple owners (including yourself), you should specify it like so. Do NOT include your own user in the user array as it will already be added.

New-PnPSite -Type TeamSite -Alias "TEST" -Title "TEST" -Wait:$false -Owners @("[email protected]","[email protected]")

Update
It also seems like that particular lcid (5129 / New Zealand) is not supported. When running the SharePoint Mangement Shell Counterpart (New-SPOSite) we get the following error:

New-SPOSite : LocaleId 5129 is not a supported locale.

7
  • OK, that explains the second error. But what about the first and the third? These are my main concern. They should just run. What is wrong with these statements?
    – teylyn
    Apr 20, 2020 at 6:37
  • It also explains the first. It waits for provisioning to complete, then times out. For the third one - your user will automatically be added as an owner, there is no need to specify it using the -owners flag. Apr 20, 2020 at 6:41
  • OK, I'll try this tomorrow, when my brain is not as frazzled as it is now.
    – teylyn
    Apr 20, 2020 at 6:45
  • Updated the answer to hopefully unfrazzle your head a bit :-) The last command should create a site in just a few seconds Apr 20, 2020 at 7:01
  • Do you have any idea how long it will take until the sites created with the first run and existing in the second run will actually show up in the SP admin center? It's been over 12 hours now and they're still not showing. If they exist, I'd like to remove them.
    – teylyn
    Apr 20, 2020 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.