Click here to Skip to main content
12,698,024 members (24,898 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: PowerShell WebParts , +
Hello everybody.

I am trying to create a regular web part page with powershell and I am not able to do it. There is no information in google about the error I get:
$spWeb = Get-SPWeb -Identity "http://server/site"
$pubWeb =[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
$pl = $pubWeb.GetAvailablePageLayouts()

Exception calling "GetAvailablePageLayouts" with "0" argument(s): "Object reference not set to an instance of an object."
At line:1 char:38
+ $pl = $pubWeb.GetAvailablePageLayouts <<<< ()
    + CategoryInfo          : NotSpecified: (: ) [ ], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

The error occurs when executing GetAvailablePageLayouts().

Any clue? Thank you.
Posted 22-Jan-13 5:47am
Updated 22-Jan-13 6:16am
v2
Comments
Sandeep Mewara 22-Jan-13 11:18am
   
Does this expect parameters: GetAvailablePageLayouts ?

is #pubWeb not null? Debug and see.
garfield185 22-Jan-13 11:20am
   
Can have, or not any parameters. Should work without any paramenters.
And, after doing $pubweb I receive

IsAllowingAllWebTemplates : True
IsAllowingAllPageLayouts : True
IsInheritingAvailableWebTemplates : False
IsInheritingAvailablePageLayouts : False
IsInheritingDefaultPageLayout : False
IsInheritingNewPageUrlToken : False
DefaultPageLayout :
NewPageUrlToken : NewPage
Web : Home
IsRoot : False
....

So I can confirm it is not null.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100