Hello guys,
Today I wrote my first PowerShell script and it felt amazing. The power of this module in Sitecore is pure genius. It lets you handle large bulk updates in the matter of seconds.
One of our requirements was to complete the Meta Tags of the entire website.
If you can imagine to go page by page it could take a day or more for one person and the risk of doing something wrong increases with the page number.
Luckily we have PowerShell ISE and it works like a charm.
<$homeItem = Get-Item -Path 'master:\content\home' $allPagesThatHaveMetaTags = $homeItem | Get-ChildItem -recurse | Where-Object {$_.MetaDescription -ne $null }
In the allPagesThatHaveMetaTags we have all items that contain the field the MetaDescription.
Now it a foreach we can go item by item and update the MetaDescription field:
$allPagesThatHaveMetaTags | ForEach-Object {
$pageDescription = 'default meta tag description in case of no article body'
$metaDescriptionItem = 'default text' if($_["Text"] -ne $null -and $_["Text"] -ne '')
{
$pageDescription = $_["Text"];
$metaDescriptionItem = 'Text field on the same item';
}
$_.Editing.BeginEdit()
$_["MetaDescription"] = $pageDescription
$_.Editing.EndEdit()
Write-Host 'Item with name ' + $_.Name + 'and ID' + $_.ID + 'has been updated with metadescription from ' + $metaDescriptionItem
}
Whith the &metaDescriptionItem I am creating a log list so I can know which items have default description and which have from the TEXT field.
Regards,
VP