0

I am planning to use SharePoint Site Scripts to provision modern sites. But, when I run command on PowerShell to add site script I am running to error.

enter image description here

I am facing the same issue, in other tenant as well. I checked this command with three developer tenants but all run into same issue. I also tried with PnPPowerShell but result into same problem.

Edit
When running the Get-SPOSiteScript command on any of those tenants, I am not getting anything but also it is not resulting into error. Following is the screenshot:

enter image description here

  • Try running the Get-SPOSiteScript cmdlet. Check whether the cmdlet runs and returns with no errors. Refer to: How to run PowerShell cmdlets to create, retrieve, update, and remove site designs and site scripts to new and existing modern site collections. github.com/SharePoint/sp-dev-docs/blob/master/docs/… – JoannaW_MSFT Apr 26 '18 at 10:15
  • I am able to run Get-SPOSiteScript successfully. It doesn't return anything, but it also not result in any error. I updated the screenshot in question. – ThinkB4Code Apr 26 '18 at 16:23
1

You are passing the string incorrectly. Enclose it inside @' and '@ as mentioned below:

$pnpTemplate = @'
{
  "$schema": "schema.json",
  "actions": [    
    {
      "verb": "createSPList",
      "listName": "Customer Tracking",
      "templateType": 100,
      "subactions": [
        {
          "verb": "SetDescription",
          "description": "List of Customers and Orders"
        }
      ]
    }
  ],
  "version": 1
}
'@

After that, you can run the SPO command as:

Add-SPOSiteScript -Title "Create Column RnD" -Content $pnpTemplate

Or the PnP command as :

Add-PnPSiteScript -Title "Create Column RnD" -Content $pnpTemplate
  • Hi @Gautam, that worked. But I was fetching the variable using $pnpTemplate = Get-Content 'C:\ProvisioningTeamplate.json' -Raw command. Do you know why this is not working? Also, in the first screenshot, it shows the variable value, when I compared that with your suggestion, I had the same output. So why that was not working? – ThinkB4Code Apr 26 '18 at 17:10
  • not 100% sure but could be an issue with string formatting. What i posted is the usage of here-strings which makes multi line reading of string easier. Check the links here, here and here – Gautam Sheth Apr 27 '18 at 5:01
  • thanks. I got it, i'll check in my environment as well, if some settings are affecting it. – ThinkB4Code Apr 27 '18 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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