Object reference not set to an instance of an object.

gokulnath palani 106 Reputation points
2024-05-16T17:50:00.6166667+00:00

Hi all,

We are trying to apply pnp-template by following this article. https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/applying-pnp-templates

I have downloaded the 'theperspectivepnp' from the site and created a 'Mysite' in my tenant. After that I tried the below command

Connect-PnPOnline https://testonlinesite-admin.sharepoint.com/
Invoke-PnPSiteTemplate -Path c:\temp\theperspective.pnp -Parameters @{"SiteUrl"="/sites/Mysite"}

I am getting a below error

'invoke-pnpsitetemplate : object reference not set to an instance of an object.'

Please advise on this.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,913 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,184 questions
{count} votes

Accepted answer
  1. Ling Zhou_MSFT 14,295 Reputation points Microsoft Vendor
    2024-05-20T05:10:23.2466667+00:00

    Hi @gokulnath palani,

    Thank you for your reply.

    1.I am sorry I didn't find out why the first method didn't work. Someone said the issue is most likely related to the Provisioning Engine. The Provisioning engine is not located in the PowerShell repo.

    2.The second method is not supported by the official documentation, it's just that I found this can successfully apply templates when I was looking for other ways to apply templates. But we only need to run the command that uses xml only once without closing the PowerShell window. Then just repeat running the command below to change the SiteTitle and SiteUrl.

    Invoke-PnPSiteTemplate -Path c:\temp\theperspective.pnp -Parameters @{"SiteTitle"="Communicationsite";"SiteUrl"="/sites/Mysite"}
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Ling Zhou_MSFT 14,295 Reputation points Microsoft Vendor
    2024-05-17T05:53:51.0866667+00:00

    Hi @gokulnath palani,

    Thank you for posting in this community.

    Is theperspective.pnp the template you want to use for your site? If so, according to the documentation you provided, the command should be this:

    Connect-PnPOnline https://<tenant>-admin.sharepoint.com/
    
    Invoke-PnPSiteTemplate -Path .\your-template-file.pnp -Parameters @{"SiteTitle"="<Title-of-your-target-site>";"SiteUrl"="/sites/<URL-of-your-target-site>"}
    

    2

    You seem to be missing the SiteTitle parameter.

    In my tests, if this parameter is missing this problem occurs:

    User's image

    If you are still having problems after using the commands above, then take the following steps:

    1.Download the theperspective template xml file.

    2.Use the following PowerShell command:

    #Config Variables
    $SiteURL = "https://crescent.sharepoint.com/sites/MySite/"
    $TemplateXML  ="C:\Users\salaudeen\Desktop\Pnp-Theme.xml"
      
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive
     
    #Apply provisioning Template
    Invoke-PnPSiteTemplate -path $TemplateXML
    

    3.After running it, you may run into problems like this. User's image

    4.Ignore the error and run this command again:

    Invoke-PnPSiteTemplate -Path .\your-template-file.pnp -Parameters @{"SiteTitle"="<Title-of-your-target-site>";"SiteUrl"="/sites/<URL-of-your-target-site>"}
    

    Here is the result:

    3


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.