M365-Site Designs(Scripts)-Add-SPOSiteScript – issue resolved – “Add-SPOSiteScript : Unexpected character encountered while parsing value: $. Path ”, line 0, position 0.” – New lesson learned :)

Hi All,
Greetings for the day π LIFE IS BEAUTIFUL π
Today new issue, new resolution π related to Site Designs, issue while deploying site scripts.
Background: In one of my training of Site Designs, I was demonstrating creating site designs using PowerShell commands. So we have created one sample Json file as below shown. This is sample and here we are changing the description of OOB document library.
{"$schema": "schema.json",
"actions": [
{
"verb": "createSPList",
"listName": "Documents",
"templateType": 101,
"subactions": [
{
"verb": "setDescription",
"description": "This is a modified document library"
}
]
}
],
"bindata": { },
"version": 1
};
Code Block 1 : M365 – Site Designs – Site Script Json file example
So I started “SharePoint online Management Shell”, connected to my local Office 365 tenant. Created above JSON file and executing “Add-SPOSiteScript” cmdlet as follows
PS C:\> $content = Get-Content -Path "C:\Prasham\Demos\Site Designs\KJSiteScript.json" -Raw
PS C:\> Add-SPOSiteScript
cmdlet Add-SPOSiteScript at command pipeline position 1
Supply values for the following parameters:
Title: "KJ Script"
Content: $content
Add-SPOSiteScript : Unexpected character encountered while parsing value: $. Path '', line 0, position 0.
At line:1 char:1
+ Add-SPOSiteScript
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-SPOSiteScript], ServerException
+ FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerException,Microsoft.Online.SharePoint.PowerShell.AddSP
OSiteScript
Code Block 2 : M365 – Site Designs – Executing command “Add-SPOSiteScript” CMDLET – Kindly please keep eye on the order in which its executing
We are getting an error –
“Add-SPOSiteScript : Unexpected character encountered while parsing value: $. Path ”, line 0, position 0.”
Error details:
PS C:> Add-SPOSiteScript cmdlet Add-SPOSiteScript at command pipeline position 1
Supply values for the following parameters:
Title: KJ Script
Content: $content
Add-SPOSiteScript : Unexpected character encountered while parsing value: $. Path ”, line 0, position 0.
At line:1 char:1
Solution / Approaches: This is strange error. Googled bit, but no luck π I thought there is an issue with JSON file. So I verified with JSONLint as

The way I am executing command is as follows:

Please notice that how, I am executing the command, one by one and not in single line. Means I just hit “Add-SPOScript” command first, then “Title” parameter and then “Content” parameter. Here is the problem.
Next I tried command different way as follows and it worked π
PS C:\> $script = '{"$schema": "schema.json","actions": [{"verb": "setSiteExternalSharingCapability","capability":"ExternalUserAndGuestSharing"}],"bindata": { },"version": 1 };'
PS C:\> $script
{"$schema": "schema.json","actions": [{"verb": "setSiteExternalSharingCapability","capability":"ExternalUserAndGuestSharing"}],"bindata": { },"version": 1 };
PS C:\> Add-SPOSiteScript -Title "External User and Guest Sharing site script" -Description "A site script to manage the
>>> guest access of a site" -Content $script
Id : c868c9db-a6b5-4e7c-ba45-2e90f3bfb3d6
Title : External User and Guest Sharing site script
Description : A site script to manage the
guest access of a site
Content :
Version : 0
Code Block 3 : M365 – Site Designs – Executing command “Add-SPOSiteScript” CMDLET – executing command in one line with content variable declared only here. Json script is reading from console only not from file
Strange behavior, when we run same command from single line it works well π
But here I want my script reading from JSON file so tried again following commands
PS C:\> $content = Get-Content -Path "C:\Prasham\Demos\Site Designs\KJSiteScript.json" -Raw
PS C:\> Add-SPOSiteScript -Title "KJ Script" -Content $content
Id : 0104332c-4b4c-43f7-a4b8-0d35a5f828c7
Title : KJ Script
Description :
Content :
Version : 0
Code Block 4 : M365 – Site Designs – Executing command “Add-SPOSiteScript” CMDLET – executing command in one line with content – Json script is reading from file

Surprisingly it worked like charm π Only thing now I executed the command in single line. This is strange behavior. But we are happy that after spending some time its working. π
Lesson Learned / Take Away : This is small thing but very important. IT will save at least hour or two. Execute this command always in single line means fully at a time.
References:
- SharePoint Site Scripts and Site Designs – April 2018 release
- Get started creating site designs and site scripts
- Site design JSON schema
Thanks for reading π Enjoy the learning Journey π
You must log in to post a comment.