$listName="A"
$siteURL="http://serverName:1111"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$list=$web.Lists[$listName]
$rootFolder = $list.RootFolder
$wikiPage = $rootFolder.Files.Add("/"+$rootFolder+"/Home.aspx", [Microsoft.SharePoint.SPTemplateFileType]::WikiPage)
$wikiItem = $wikiPage.Item
$wikiItem[[Microsoft.SharePoint.SPBuiltInFieldId]::WikiField] = "Template Preview"
$wikiItem.UpdateOverwriteVersion()
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

sandeep singhPosted Aug 22, 2014, 4:17 AM
Script is identical to yours only the Listname="SitePages" and URL="http://wfetest/sites/labteam" differs. SharePoint cmdlets are loaded. Any suggestions. You cannot call a method on a null-valued expression. At line:8 char:36 + $wikiPage = $rootFolder.Files.Add <<<< ("/"+$rootFolder+"/Home1.aspx", [Microsoft.SharePoint.SPTemplateFileType]::WikiPage) + CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Cannot index into a null array. At line:10 char:13 + $wikiItem[ <<<< [Microsoft.SharePoint.SPBuiltInFieldId]::WikiField] = "Template Preview" + CategoryInfo : InvalidOperation: (c33527b4-d920-4587-b791-45024d00068a:Guid) [], RuntimeException + FullyQualifiedErrorId : NullArray You cannot call a method on a null-valued expression. At line:11 char:35 + $wikiItem.UpdateOverwriteVersion <<<< () + CategoryInfo : InvalidOperation: (UpdateOverwriteVersion:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
Adam CarlsonPosted Feb 29, 2012, 5:42 PM
Script is identical to yours only the Listname="Document Wiki" and URL="http://wfetest/sites/labteam" differs. SharePoint cmdlets are loaded. Any suggestions. You cannot call a method on a null-valued expression. At line:8 char:36 + $wikiPage = $rootFolder.Files.Add <<<< ("/"+$rootFolder+"/Home1.aspx", [Microsoft.SharePoint.SPTemplateFileType]::WikiPage) + CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Cannot index into a null array. At line:10 char:13 + $wikiItem[ <<<< [Microsoft.SharePoint.SPBuiltInFieldId]::WikiField] = "Template Preview" + CategoryInfo : InvalidOperation: (c33527b4-d920-4587-b791-45024d00068a:Guid) [], RuntimeException + FullyQualifiedErrorId : NullArray You cannot call a method on a null-valued expression. At line:11 char:35 + $wikiItem.UpdateOverwriteVersion <<<< () + CategoryInfo : InvalidOperation: (UpdateOverwriteVersion:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull