I’ve written a Powershell script that can create X amount of Sharepoint sites and apply a template to them (a .pnp file). A majority of the time, it’ll run fine; however, occasionally, I will get ‘CSOM Service Exception’. It is always on different parts of the template application too – i.e. there is no noticeable pattern to it. It’ll just randomly occur.
If I can’t get a solution, I just want to get more accurate information on where or why it is appearing. I google it and get nothing. (I’m relatively new to all this…)
These are the applicable parts of the code (relating to applying the template):
$localTemplatePath = "C:tempcontosoworks.pnp"
$siteTitle = "Division of Time Machine Maintenance"
$siteUrl = "https://xxxxxxxxxx.sharepoint.com/sites/
DivisionofTimeMachineMaintenance-MT59"
$benefitsTitle = "Time Machine Maintenance Benefits"
$benefitsUrl = "https://xxxxxxxxxxxxx.sharepoint.com/sites/
DivisionofTimeMachineMaintenance-MT59-benefits"
Invoke-PnPTenantTemplate -Path $localTemplatePath -Parameters @{
"SiteTitle" = $siteTitle
"SiteUrl" = $siteUrl
"BenefitsSiteTitle" = $benefitsTitle
"BenefitsSiteUrl" = $benefitsUrl
}
The .pnp file that is being applied is a slightly modified version of the template from here
It’s during this process of applying the template that the CSOM error occurs. So if it’s not the script, then it must be an issue with the template.
I’ve tried getting more verbose errors outputs and trying to get more information on the error; however, it is often very vague. The best I can get is:
Message : CSOM service exception
Stacktrace : at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in
c:buildsrcCommandsBasePnPConnectedCmdlet.cs:line 101
at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in
c:buildsrcCommandsBasePnPSharePointCmdlet.cs:line 131
at System.Management.Automation.CommandProcessor.ProcessRecord()
ScriptLineNumber : 94
Sometimes, it will occur and prevent me from applying the template and other times it’ll run through to completion with no issues (i.e. the sites are created and the template is added successfully via the powershell script). It’s very chaotic.
Judas Jefferson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.