Click here to Skip to main content
Rate this: bad
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 4:47am
Edited 22-Jan-13 5:16am
Sandeep Mewara at 22-Jan-13 11:18am
Does this expect parameters: GetAvailablePageLayouts ?
is #pubWeb not null? Debug and see.
garfield185 at 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
0 OriginalGriff 6,034
1 Sergey Alexandrovich Kryukov 4,838
2 Peter Leow 3,129
3 Maciej Los 3,079
4 DamithSL 2,465

Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2014
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