Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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))
 {
  $item.file.CheckOut();

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

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


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


  write-host $item.name "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

2 Answers 2

up vote 0 down vote accepted

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

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

with

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_.

$item["WikiField"]

share|improve this answer

Your Answer

 
discard

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.