SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying below powershell script for change wiki content

       Add-PSSnapin microsoft.sharepoint.powershell  -ea silentlycontinue

$web = Get-SPWeb "http://dooku/enterprisewiki"
$list = $web.Lists["Site Pages"]

function upgradefeature($search,$replace)

foreach ($item in $list.items)

 if ($item["ows_WikiField"].contains($search))

  do {write-host -NoNewline .;Start-Sleep -m 10;} while ($item.file.CheckOutStatus -eq "None")

  $item["ows_WikiField"] = $item["ows_WikiField"].replace($search ,$replace );

  sleep 1
  $item.file.CheckIn("checked in by administrator");

  write-host $ "modified" $search "replace with" $replace   -foregroundcolor red



$replace1 = "enterprisewiki/pages/"

$search1 = "techs/Procedures%20%20Policies/"
upgradefeature $search1 $replace1 

This script works fine for me. When i create another custom wiki library name 'page-test' and try this code with change of this line

  $list = $web.Lists["page-test"]

it shows me error

You cannot call a method on a null-valued expression. At C:\Users\wikilinks\Desktop\Test.ps1:13 char:37 + if ($item["ows_WikiField"].contains <<<< ($search)) + CategoryInfo : InvalidOperation: (contains:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

why this custom wiki library not getting this field ows_WikiField or there is some other issue? please help me. thanks

share|improve this question
up vote 0 down vote accepted

Are you sure the WikiField has content? I'd replace

if ($item["ows_WikiField"].contains($search)) 


if ($item["ows_WikiField"] -and $item["ows_WikiField"].contains($search)) 
share|improve this answer
thanks per for reply but i have wiki pages with content. so why wikifield not found or it's give me null reference. – Vishal_Sharepoint Mar 30 '12 at 7:11

SP2010 wiki page content field is called WikiField. Drop the ows_.


share|improve this answer

Your Answer


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.