Question

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

Était-ce utile?

La solution

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

Autres conseils

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

$item["WikiField"]

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top