Creating Content Reports With Sitecore PowerShell

Advanced System Reporter used to be my go-to module for running content reports, but support for this module ended a while ago and it's time to look for something new. Sitecore PowerShell is a massively powerful tool, used for countless reasons when managing a Sitecore instance. I could write a few dozen posts covering all the possibilities, but today I'm only going to show you show to generate a simple content report.

 

Installing Sitecore PowerShell

This feature isn't available out of the box, so we need to install a module. I'm using Sitecore 9.3 initial release, so PowerShell 6.0 is going to be used according to their compatibility table. The file I retrieved was Sitecore.PowerShell.Extensions-6.0.zip, but use the one that's best for your installation.

When using with Sitecore's installation wizard you'll see there's some pre and post installation steps.



Once the module has installed, you're going to want to move on over to App_Config\Include\Spe\ and enable that Spe.IdentityServer.config file, which allows the module to work with your identity Server.

 

Creating a Script

I keep the scripts for reporting in a dedicated area apart from the module's standard ones, so it's easier to serialize and manage. I've created an item called Custom Reports, of type PowerShell Script Library in the path /sitecore/system/Modules/PowerShell/Script Library/SPE/Reporting/Content Reports/Reports/. In here, I've created an item called Sample Report, of type PowerShell Script.

 


 Once this item is created, you'll see that an elevated session is required to edit it. This will allow you to enter your script in the Script Body field.



Now, there's authoring tools available to make scripts that PowerShell will use, but the syntax is really straightforward. I've included a sample script which will give a report for all Field Type items in the Forms area of Settings.

 

$items = Get-ChildItem -Path "master:/sitecore/system/Settings/Forms/" -Recurse | where-object { $_.TemplateName -eq "Field Type" }
if($items.Count -eq 0){
    Show-Alert "There are no items found in this report."
} else {
$props = @{
    Title = "Item Report"
    InfoTitle = "Data"
    InfoDescription = "Lists all items of type Field Type."
    PageSize = 25
}
$items | Show-ListView @props -Property 
    @{Label="Created"; Expression={$_."__Created"} },
    @{Label="Display Name"; Expression={$_."__Display Name"}},
    @{Label="View Path"; Expression={$_."View Path"}}
}
Close-Window

 

Running the Script

From the start menu, navigate to Reporting Tools -> PowerShell Reports to find the one you created. On execution you will see the script's output, along with some export options.




That's it! I kept this basic to lay the groundwork for more complicated reporting options, but as you can see it's not hard to do. We serialize these reports into our project for deployments and cross-developer sharing, and I recommend you manage these items in the same way.