SOLVED

Creating modern site with PnP powershell

Silver Contributor

I'm getting the following error with the latest PnP Online module. Does this work for anyone?

 

New-PnPSite -Type TeamSite -Title Portfolio -Alias pc
New-PnPSite : Object reference not set to an instance of an object.
At line:1 char:1
+ New-PnPSite -Type TeamSite -Title Portfolio -Alias pc
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [New-PnPSite], NullReferenceException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.NewSite

 

@Erwin van Hunen

8 Replies
Did you run connect-pnponline first?
Not at a PC but command looks right. Try and enable debug level tracing.

https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/SetPnPTraceLog.md

@Kevin McDonnell, Thanks, I have enabled the log and it is empty. That got me thinking and when I add -Verbose, I get the following :
New-PnPSite : {"error":{"code":"-1, System.Data.Services.Client.DataServiceClientException","message":{"lang":"en-US","value":"{\"odata.error\":{\"code\":\"Request_BadRequest\",\"mess
age\":{\"lang\":\"en\",\"value\":\"Invalid value specified for property 'mailNickname' of resource 'Group'.\"},\"requestId\":\"6a52863d-e6c9-49f7-a696-ec373b4e4add\",\"date\":\"2017-1
0-24T16:42:25\",\"values\":[{\"item\":\"PropertyName\",\"value\":\"mailNickname\"},{\"item\":\"PropertyErrorCode\",\"value\":\"InvalidValue\"}]}}"}}}
At line:1 char:1
+ New-PnPSite -Type TeamSite -Title Test4 -Alias 'Test 4' -Description  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [New-PnPSite], Exception
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.NewSite

 

It appears that the Alias attribute cannot accept strings that contain spaces. @Erwin van Hunen is this an expected limitation?

best response confirmed by VI_Migration (Silver Contributor)
Solution

I initially was thinking it was due to the way you login, as we fixed an issue with using the -WebLogin parameters. But indeed, in your case it is the mailnickname that is causing the issue, it is not related to your login. Indeed, the Alias parameter value cannot contain a space. 

 

I'll add a check in the backend code for that.

Thanks, I also realized that I should not connect to the tenant-admin site. Could you add that to the documentation or is that something I should do through a pull request?

 

Also, why is the MailNickname attribute, referred to as Alias? that confused me because alias already has its own meaning in powershell

I'll add that.

  1. @Erwin van Hunen 

I get the same issue with the following version.
---- -----------------
PnP.PowerShell 1.4.0

----------------------

# used for the coonection
$HashArguments = @{
    ClientId               = $env:GRAPH_APP_ID
    ClientSecret           = $env:GRAPH_APP_SECRET
    Url                    = $adminWebUrl 
}
$adminConn = Connect-PnPOnline @HashArguments -ReturnConnection
1 best response

Accepted Solutions
best response confirmed by VI_Migration (Silver Contributor)
Solution

I initially was thinking it was due to the way you login, as we fixed an issue with using the -WebLogin parameters. But indeed, in your case it is the mailnickname that is causing the issue, it is not related to your login. Indeed, the Alias parameter value cannot contain a space. 

 

I'll add a check in the backend code for that.

View solution in original post