$webApp = "http://acme" $crRx = "Copyright\s*201[0-5]" $rplTxt = "Copyright 2016" $siteColls = get-spsite -Limit ALL -WebApplication $webApp function ProcessSite([Microsoft.SharePoint.SPSite]$site){ $site.AllWebs|%{ProcessWeb $_.Url} } function ProcessWeb([string]$webUrl){ $web = get-spweb $webUrl write-host "Processing: $($web.Url)" $wSRUrl = $web.ServerRelativeUrl if($wSRUrl -eq "/"){ $wSRUrl = "" } $catalogRx = "^$($wSRUrl)/_catalogs/masterpage" $masterUrl = $web.MasterUrl if($masterUrl -match $catalogRx){ $tempFileName = [System.IO.Path]::GetTempFileName() $f = $web.GetFile($masterUrl) if($f.Exists){ write-host "** $($masterUrl): $($f.Length)" $ss = $f.OpenBinaryStream([Microsoft.SharePoint.SPOpenBinaryOptions]::SkipVirusScan) $bytes = New-Object Byte[] $($ss.Length) $ss.Read($bytes, 0, $ss.Length) $ss.Close() $content = [System.Text.Encoding]::UTF8.GetString($bytes) if($content -ne $null -and $content -ne ""){ if($content -match $crRx){ write-host "!!!!Found Copyrights" $newContent = $content -replace $crRx,$rplTxt $newContentBytes = [System.Text.Encoding]::UTF8.GetBytes($newContent) $f = $web.GetFile($masterUrl) if($f.RequiresCheckout){ $f.CheckOut() } $f.SaveBinary($newContentBytes) if($f.RequiresCheckout){ $f.CheckIn("Copyrights update", [ Microsoft.SharePoint.SPCheckinType]::MajorCheckIn) $f.Approve("Copyrights update") } } else { write-host "----No Copyrights" } } else { write-host "The GetFile function returned empty string" } } else { write-host "File not exists" } } else { write-host "No local MasterPage" } } $siteColls|%{ProcessSite $_}