I wrote a Powershell script that creates SharePoint sites and pages based on an XML file to generate about 200 sites and more pages to build a specific structure.
The basic steps it does repeatedly (roughly below), given a newly created [Microsoft.SharePoint.SPWeb]$web:
$pubSite = new-object Microsoft.SharePoint.Publishing.PublishingSite($web.Url)
$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pagesLib = $pubWeb.GetPublishingPages()
$contentType = $pubSite.ContentTypes["Name of Content Type"]
$pageLayout = $pubSite.GetPageLayouts($contentType, $FALSE)
$newPage = $pagesLib.Add("pagename.aspx", $pageLayout)
I've run this on all my Dev servers rebuilt several times and ALWAYS works. But when I tried to run the exact same script at one of our clients' with supposedly the same spec and build Windows Server 2k8 R2 servers, it always fails on the LAST LINE with:
Exception calling "Add" with "2" argument(s): "No parameterless constructor def ined for this object."
Case 1 above, was using the SharePoint 2010 Management Shell console (Run as Administrator) - for which it NEVER works
The strange thing is the EXACT SAME script, server and parameters WORK if I install Windows Powershell ISE on the clients' server and run the script in THAT.
Is there any significant difference running Powershell scripts between the Powershell ISE and the SharePoint 2010 Management shell? Possibly in terms of security, which might explain why it would NOT work using the SharePoint shell but would work using ISE
My guess is that the clients' server must have some manner of additional security setting from the organisation policy that wouldn't normally be deployed on Development boxes, that affects the privileges of running scripts between the 2 consoles.
Would appreciate ANY comments. Seriously at the end of my rope.