0

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

0

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)) 
  • 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
1

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

$item["WikiField"]

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.