Report Sitecore Content Changes Using A Powershell Script

Report On Changes Made To Your Content

This short blog post will share a effective powershell script that will create a report and show you how much content has changed between a user specified date range. This is especially useful to convey to stakeholders what content has changed in a period of time.

<# .synopsis="" lists="" the="" content="" diff="" between="" dates="" #=""> $database = "master" $root = Get-Item -Path (@{$true="$($database):\content\home"; $false="$($database):\content"}[(Test-Path -Path "$($database):\content")]) $periodOptions = [ordered]@{Before=1;After=2;} $selectedPeriod = 2 $daysToFilter $settings = @{ Title = "Report Filter" OkButtonName = "Proceed" CancelButtonName = "Abort" Description = "Filter the results for items updated on or after the specified date" Parameters = @( @{ Name="root"; Title="Choose the report root"; Tooltip="Only items from this root will be returned."; }, @{ Name = "selectedDate" Value = [System.DateTime]::Now Title = "Date" Tooltip = "Select the start date for the diff" Editor = "date time" }, @{ Name = "daysToFilter" Value = 28 Title = "Number of Days" Tooltip = "Select the amount of days you want to filter by" } ) Icon = [regex]::Replace($PSScript.Appearance.Icon, "Office", "OfficeWhite", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) ShowHint = $true } $result = Read-Variable @settings if($result -ne "ok") { Exit } filter Where-LastUpdated { param( [Parameter(Mandatory=$true,ValueFromPipeline=$true)] [Sitecore.Data.Items.Item]$Item, [datetime]$Date=([datetime]::Today), [switch]$IsBefore, [int]$MaxDays ) $convertedDate = [Sitecore.DateUtil]::IsoDateToDateTime($item.Fields[[Sitecore.FieldIDs]::Updated].Value) $isWithinDate = $false if($IsBefore.IsPresent) { if($convertedDate -le $Date) { $isWithinDate = $true } } else { if($convertedDate -ge $Date) { $isWithinDate = $true } } if($isWithinDate) { if($MaxDays -lt [int]::MaxValue) { if([math]::Abs(($convertedDate - $Date).Days) -le $MaxDays) { $item } } else { $item } } } $items = @($root) + @(($root.Axes.GetDescendants())) | Where-LastUpdated -Date $selectedDate -IsBefore:($selectedPeriod -eq 1) -MaxDays $daysToFilter | Initialize-Item <# add="" conditionals="" here="" to="" filter="" out="" whatever="" items="" you="" don't="" want,="" example="" below="" $filtereditems="$items" |="" where-object="" {$_."__updated="" by"="" -ne="" 'ad\esong'}="" |="" where-object="" {$_."__updated="" by"="" -ne="" 'sitecore\fishtankprodadmin'}="" |="" where-object="" {$_."__updated="" by"="" -ne="" 'sitecore\admin'}="" #=""> $filteredItems = $items $message = "before" if($selectedPeriod -ne 1) { $message = "after" } if($items.Count -eq 0) { Show-Alert "There are no items updated on or after the specified date" } else { $props = @{ Title = "Items Last Updated Report" InfoTitle = "Items last updated $($message) date" InfoDescription = "Lists all items last updated $($message) the date selected." PageSize = 25 } $filteredItems | Show-ListView @props -Property @{Label="Name"; Expression={$_.DisplayName} }, @{Label="Updated"; Expression={$_.__Updated} }, @{Label="Updated by"; Expression={$_."__Updated by"} }, @{Label="Created"; Expression={$_.__Created} }, @{Label="Created by"; Expression={$_."__Created by"} }, @{Label="Template Name"; Expression={$_.TemplateName} }, @{Label="Path"; Expression={$_.ItemPath} } } Close-Window

How To Use The Script

When you run the script you will be presented with three fields.

After running the script you will be presented with three fields in the Report Filter

The first option you can specify a root, I would suggest trying this on a smaller sized tree to get the results that you prefer.

The second option is the start date, you should select the day you want to start comparing.

The third option is how many days you want the filter to go up to. An example would be your start date is December 1st, and you filter for 28 days, that would be December 29th, you would be getting any items that have changed in that time period.

Reporting To Stakeholders

Using this, you can present to stakeholders how much content has changed, there is even an option after the report is finished to print it in an excel format.

Screenshot of the Items Last Updated Report to show how much content has changed


I hope this gives stakeholders an easy way to see what content has changed in between a date range.

Hey, Developers!

We're on the look out for talented developers to join our team.

Think you have what it takes?