SOLVED

Creating modern site with PnP powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-118742%22%20slang%3D%22en-US%22%3ECreating%20modern%20site%20with%20PnP%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-118742%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20getting%20the%20following%20error%20with%20the%20latest%20PnP%20Online%20module.%20Does%20this%20work%20for%20anyone%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENew-PnPSite%20-Type%20TeamSite%20-Title%20Portfolio%20-Alias%20pc%3CBR%20%2F%3ENew-PnPSite%20%3A%20Object%20reference%20not%20set%20to%20an%20instance%20of%20an%20object.%3CBR%20%2F%3EAt%20line%3A1%20char%3A1%3CBR%20%2F%3E%2B%20New-PnPSite%20-Type%20TeamSite%20-Title%20Portfolio%20-Alias%20pc%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3A%20WriteError%3A%20(%3A)%20%5BNew-PnPSite%5D%2C%20NullReferenceException%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20EXCEPTION%2CSharePointPnP.PowerShell.Commands.NewSite%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F122%22%20target%3D%22_blank%22%3E%40Erwin%20van%20Hunen%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-118742%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-119689%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20modern%20site%20with%20PnP%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-119689%22%20slang%3D%22en-US%22%3E%3CP%3EI'll%20add%20that.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-119688%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20modern%20site%20with%20PnP%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-119688%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%2C%20I%20also%20realized%20that%20I%20should%20not%20connect%20to%20the%20tenant-admin%20site.%20Could%20you%20add%20that%20to%20the%20documentation%20or%20is%20that%20something%20I%20should%20do%20through%20a%20pull%20request%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20why%20is%20the%20MailNickname%20attribute%2C%20referred%20to%20as%20Alias%3F%20that%20confused%20me%20because%20alias%20already%20has%20its%20own%20meaning%20in%20powershell%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-119687%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20modern%20site%20with%20PnP%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-119687%22%20slang%3D%22en-US%22%3E%3CP%3EI%20initially%20was%20thinking%20it%20was%20due%20to%20the%20way%20you%20login%2C%20as%20we%20fixed%20an%20issue%20with%20using%20the%20-WebLogin%20parameters.%20But%20indeed%2C%20in%20your%20case%20it%20is%20the%20mailnickname%20that%20is%20causing%20the%20issue%2C%20it%20is%20not%20related%20to%20your%20login.%20Indeed%2C%20the%20Alias%20parameter%20value%20cannot%20contain%20a%20space.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'll%20add%20a%20check%20in%20the%20backend%20code%20for%20that.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-119651%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20modern%20site%20with%20PnP%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-119651%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F42708%22%20target%3D%22_blank%22%3E%40Kevin%20McDonnell%3C%2FA%3E%2C%20Thanks%2C%20I%20have%20enabled%20the%20log%20and%20it%20is%20empty.%26nbsp%3BThat%20got%20me%20thinking%20and%26nbsp%3Bwhen%20I%20add%20-Verbose%2C%20I%20get%20the%20following%20%3A%3CBR%20%2F%3ENew-PnPSite%20%3A%20%7B%22error%22%3A%7B%22code%22%3A%22-1%2C%20System.Data.Services.Client.DataServiceClientException%22%2C%22message%22%3A%7B%22lang%22%3A%22en-US%22%2C%22value%22%3A%22%7B%5C%22odata.error%5C%22%3A%7B%5C%22code%5C%22%3A%5C%22Request_BadRequest%5C%22%2C%5C%22mess%3CBR%20%2F%3Eage%5C%22%3A%7B%5C%22lang%5C%22%3A%5C%22en%5C%22%2C%5C%22value%5C%22%3A%5C%22Invalid%20value%20specified%20for%20property%20'mailNickname'%20of%20resource%20'Group'.%5C%22%7D%2C%5C%22requestId%5C%22%3A%5C%226a52863d-e6c9-49f7-a696-ec373b4e4add%5C%22%2C%5C%22date%5C%22%3A%5C%222017-1%3CBR%20%2F%3E0-24T16%3A42%3A25%5C%22%2C%5C%22values%5C%22%3A%5B%7B%5C%22item%5C%22%3A%5C%22PropertyName%5C%22%2C%5C%22value%5C%22%3A%5C%22mailNickname%5C%22%7D%2C%7B%5C%22item%5C%22%3A%5C%22PropertyErrorCode%5C%22%2C%5C%22value%5C%22%3A%5C%22InvalidValue%5C%22%7D%5D%7D%7D%22%7D%7D%7D%3CBR%20%2F%3EAt%20line%3A1%20char%3A1%3CBR%20%2F%3E%2B%20New-PnPSite%20-Type%20TeamSite%20-Title%20Test4%20-Alias%20'Test%204'%20-Description%26nbsp%3B%20...%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3A%20WriteError%3A%20(%3A)%20%5BNew-PnPSite%5D%2C%20Exception%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20EXCEPTION%2CSharePointPnP.PowerShell.Commands.NewSite%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20appears%20that%20the%20Alias%20attribute%20cannot%20accept%20strings%20that%20contain%20spaces.%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F122%22%20target%3D%22_blank%22%3E%40Erwin%20van%20Hunen%3C%2FA%3E%20is%20this%20an%20expected%20limitation%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-118862%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20modern%20site%20with%20PnP%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-118862%22%20slang%3D%22en-US%22%3ENot%20at%20a%20PC%20but%20command%20looks%20right.%20Try%20and%20enable%20debug%20level%20tracing.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Fblob%2Fmaster%2FDocumentation%2FSetPnPTraceLog.md%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Fblob%2Fmaster%2FDocumentation%2FSetPnPTraceLog.md%3C%2FA%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-118861%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20modern%20site%20with%20PnP%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-118861%22%20slang%3D%22en-US%22%3Eyes%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-118858%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20modern%20site%20with%20PnP%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-118858%22%20slang%3D%22en-US%22%3EDid%20you%20run%20connect-pnponline%20first%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2245471%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20modern%20site%20with%20PnP%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2245471%22%20slang%3D%22en-US%22%3E%3COL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F122%22%20target%3D%22_blank%22%3E%40Erwin%20van%20Hunen%3C%2FA%3E%26nbsp%3B%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EI%20get%20the%20same%20issue%20with%20the%20following%20version.%3CBR%20%2F%3E----%20-----------------%3CBR%20%2F%3EPnP.PowerShell%201.4.0%3C%2FP%3E%0A%3CP%3E----------------------%3C%2FP%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3E%23%20used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3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%24adminWebUrl%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3E%24adminConn%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EConnect-PnPOnline%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%40HashArguments%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-ReturnConnection%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E
Respected 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 Dean Gross (Respected 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