I tried to add a wikipage in the wikipage library using the code provided by Vijai Anand Ramalingam on c-sharpcorner.com.

I'm copy-pasting the script here to avoid dead link issues preventing future readers from accessing it. I obviously replaced all the variables to allow the script to suits my local environnement.

$site=Get-SPSite $siteURL
$rootFolder = $list.RootFolder
$wikiPage = $rootFolder.Files.Add("/"+$rootFolder+"/Home.aspx", [Microsoft.SharePoint.SPTemplateFileType]::WikiPage)
$wikiItem = $wikiPage.Item
$wikiItem[[Microsoft.SharePoint.SPBuiltInFieldId]::WikiField] = "Template Preview" 

This code is not working because it throws the following error:

You cannot call a method on a null-valued expression

$wikiPage = $rootFolder.Files.Add("/"+$rootFolder+"/Home7.aspx", [Microsoft.Sh ...



$wikiPage = $rootFolder.Files.Add("/"+$rootFolder+"/Home.aspx", [Microsoft.SharePoint.SPTemplateFileType]::WikiPage)


$wikiPage = $rootFolder.Files.Add($rootFoler.ServerRelativeUrl + "/Home.aspx", [Microsoft.SharePoint.SPTemplateFileType]::WikiPage)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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