none
PowerShell/CSOM CMSPublishing#0 exception RRS feed

  • Question

  • I'm trying to execute a Powershell script that uses CSOM to create Publishing webs.  Each ClientContext tries to create exactly one OOTB CMSPublishing#0 web and I get the error (sometimes):
    Error : Exception calling "ExecuteQuery" with "0" argument(s): "Provisioning did not succeed. Details: Failed to initialize some site properties for Web at Url: 'https://..../hr/benefits' OriginalException: The request uses too many resources.
    I understand that one cannot bundle too many requests at once because of the request limit being 2 MB or so, but this is being done with a new ClientContext instance with no outstanding requests (verified by property inspection) and sometimes it works, sometimes it doesn't.

    How can provisioning a single web in a single-use client context generate a request size greater than 2MB?  How can I get around this issue?  (Btw, yesterday the powershell script ran to completion at least 5 times with no errors, but today it won't - so what's causing this, too?). 

    Another odd thing is when I made a whitespace change in the file (inside a comment), it started executing just fine for 10 executions.  I then closed out PowerShell ISE and when I reopened it, same errors.

    Thanks,

    Steve

    Monday, March 23, 2015 5:30 PM

Answers

  • Hi Steve,

    For this issue, I recommend to make sure that the SharePoint Server Publishing Infrastructure is activated on the Site collection features firstly.

    Would you mind of providing your PowerShell code for reproducing this issue?

    I tested the CSOM PowerShell command below to create publishing webs in my environment, and it worked fine.

    I recommend to run the command in your environment to see how it works.

    Add-PSSnapin Microsoft.SharePoint.PowerShell
    
    Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
     
    Function New-Site()
    {
     param(
     [Parameter(Mandatory=$true)][string]$webappurl,
     [Parameter(Mandatory=$true)][string]$siteurl,
     [Parameter(Mandatory=$false)][string]$sitetitle,
     [Parameter(Mandatory=$false)][string]$sitedescription,
     [Parameter(Mandatory=$false)][string]$webTemplate,
     [Parameter(Mandatory=$false)][int]$lcid,
     [Parameter(Mandatory=$false)][bool]$UseSamePermissionsAsParentSite,
     [Parameter(Mandatory=$false)][System.Net.NetworkCredential]$credentials
     )
    
     try
     {
       $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webappurl)
       $ctx.Credentials = $credentials
       $webCreationInformation = New-Object Microsoft.SharePoint.Client.WebCreationInformation
       $webCreationInformation.Url = $siteurl
       $webCreationInformation.Title = $sitetitle
       $webCreationInformation.Description = $sitedescription
       $webCreationInformation.UseSamePermissionsAsParentSite = $UseSamePermissionsAsParentSite
       $webCreationInformation.Language = $lcid 
       $webCreationInformation.WebTemplate = $webTemplate
       $newWeb = $ctx.Web.Webs.Add($webCreationInformation)
       $ctx.Load($newWeb) 
       $ctx.ExecuteQuery()
    
       if(!$?) {
         Throw "Unable to create new site"
       }
       Write-Host "Site created successfully." -ForegroundColor Green
    
     }
     catch
     {
       Write-Host("Error while creating site. Error -->> " + $_.Exception.Message) -ForegroundColor Red
     }
    }
    
    $webappurl = 'http://webappURL'
    $siteurl = 'SomeSite'
    $sitetitle = 'Some Title'
    $sitedescription = 'Some site description' 
    $WebTemplate = "CMSPUBLISHING#0"
    $Lcid = 1033
    $UseSamePermissionsAsParentSite = $true
    $credentials = Get-Credential
    
    New-Site $webappurl $siteurl $sitetitle $sitedescription $WebTemplate $Lcid $UseSamePermissionsAsParentSite 

    Thanks,

    Victoria


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.



    Wednesday, March 25, 2015 5:07 AM
    Moderator