Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

Check for null for variables, especially $pageLayout and $contentType

If ( $pageLayout )
{
    # use variable
}

I guess this is on SP2007 since you are not using cmdlets such as Get-SPWeb ?

share|improve this answer
    
Thanks. This is 2010. can you get a PublishingWeb object from Get-SPWeb? It's different, right? PublishingWeb vs SPWeb... Also I kind of already have an idea that it's the $pageLayout line becoming $NULL which is why it fails, but I'm wondering why it doesn't fail if I run the exact same script on ISE –  zee Jun 17 '11 at 2:10
add comment

The one time I saw the exception "No parameterless constructor def ined for this object." was when I used comments in a pagelayout within a webpartzone. I really don't know if this is helping you, but could you please check this?

share|improve this answer
    
Thanks. I've got a comment above the zone but not within it... some have suggested that the tag <WebPartPages:webpartzone> was case-sensitive, i.e. it should be <WebPartPages:WebPartZone> which is why it breaks, but that seems bizarre.. –  zee Jun 17 '11 at 2:14
add comment

Well, there's one thing I see that CAN go wrong:

$pageLayout = $pubSite.GetPageLayouts($contentType, $FALSE)

This can give you more than one page layout, since a content type can be associated with multiple page layouts...

Cheers Eau

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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