Replace Text within multiple Wikipages using PowerShell

 Script for Sharepoint 2010 Enterprise Wikis!

$logfile = "c:\logfile.txt"
$web = Get-SPWeb "http://intranet/wikiurl"
$list = $web.GetList(($web.ServerRelativeUrl.TrimEnd("/") + "/Wiki%20Pages"))
 

$search = "search_text"
$replace = "replace_test"

(get-date).ToString() + " >>> Script Startet >> Parameter: Search = " + $search + " | Replace = "+$replace   | add-content $logfile
(get-date).ToString() + " >>> Script Startet >> Parameter: Search = " + $search + " | Replace = "+$replace   | add-content $logfile
foreach ($item in $list.items)
{
 

if ($item["Page Content"].contains($search))
{

$item.file.CheckOut();

(get-date).ToString() + " >>> " +  $item.name + " checked out"   | add-content $logfile

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

 
 

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

$item.update();

(get-date).ToString() + " >>> " +  $item.name + " modified"   | add-content $logfile

(get-date).ToString() + " >>> " +  $search + " changed by " + $replace  | add-content $logfile

sleep 1

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

(get-date).ToString() + " >>> " +  $item.name + " checked in"   | add-content $logfile

 
 

write-host $item.name "modified" -foregroundcolor red

}

}

 
 

_________________________________________________________________________________

Script for migrated SharePoint 2007 Wikis to SP 2010!

 
 

["Page Content"] has been replaced by ["ows_WikiField"]

 
 

 
 

 
 

$logfile = "c:\logfile.txt"

$web = Get-SPWeb "http://intranet/wikiurl"

$list = $web.GetList(($web.ServerRelativeUrl.TrimEnd("/") + "/Wiki%20Pages"))

 
 

$search = "search_text"

$replace = "replace_test"

 
 

 
 

(get-date).ToString() + " >>> Script Startet >> Parameter: Search = " + $search + " | Replace = "+$replace   | add-content $logfile

(get-date).ToString() + " >>> Script Startet >> Parameter: Search = " + $search + " | Replace = "+$replace   | add-content $logfile

foreach ($item in $list.items)

{

 
 

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

 {

  $item.file.CheckOut();

  (get-date).ToString() + " >>> " +  $item.name + " checked out"   | add-content $logfile

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

  (get-date).ToString() + " >>> " +  $item.name + " modified"   | add-content $logfile

  (get-date).ToString() + " >>> " +  $search + " changed by " + $replace  | add-content $logfile

  sleep 1

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

  (get-date).ToString() + " >>> " +  $item.name + " checked in"   | add-content $logfile

 
 

  write-host $item.name "modified" -foregroundcolor red

 }

}