Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Created November 24, 2015 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/0b607d7ae89b984fc4d1 to your computer and use it in GitHub Desktop.
Save michaellwest/0b607d7ae89b984fc4d1 to your computer and use it in GitHub Desktop.
Replaces all instances of the Google Analytics click event with an empty string.
$path = "master:\content\"
$items = Get-ChildItem -Path $path -Recurse
$fields = @("Ads","Body","Carousel","HtmlText","Left Body","Location Body","Mid Body","Quick Links and News","Search Location")
$updateCounts = @{}
$fields | ForEach-Object { $updateCounts[$_] = 0 }
foreach($item in $items) {
Write-Host "Processing $($item.Id) : $($item.Name)"
foreach($field in $fields) {
if($item.$field) {
Write-Host "Updating $($field)"
$fieldValue = $item.$field -replace ' onclick="_gaq.*\);"',''
$updateCounts[$field] += 1
$item.$field = $fieldValue
}
}
}
$updateCounts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment