3

I'm defining serialization, and I'd like a report of items loaded by Sitecore so I can make sure I'm avoiding those paths. Is it possible to get a CSV listing of all items in the stock items-as-resources (a.k.a. protocol buffers) using SPE?

1 Answer 1

4

Yes, you can use a script like this to do that:

$di = [Sitecore.DependencyInjection.ServiceLocator]::ServiceProvider
$rl = $di.GetService([Sitecore.Data.DataProviders.ReadOnly.Protobuf.IResourceLoader])
$pdp = [Sitecore.Data.DataProviders.ReadOnly.Protobuf.ProtobufDataProvider]::new([String[]]@("/App_Data/items/master", "/sitecore modules/items/master"), $rl)
$ids = $pdp.DataSet.Definitions.Values | Select ID

$ids | ForEach-Object {
    Get-Item master -id $_.ID | Select ID, Name, FullPath
} | Sort-Object FullPath | Export-CSV c:\inetpub\wwwroot\App_Data\Packages\ProtoBuffReport.csv

A few notes:

  1. We are using Sitecore Dependency Injection to resolve the ResourceLoader dependency.
  2. The two paths passed to the constructor are visible in ShowConfig.aspx.
  3. The DataSet.Definitions object is used to support ID lookup, so looks to me like the right place to get the complete list of items.
  4. The script above would pick up changes applied to this data by SQL Server items. Since I'm just pulling the path, I think the only risk is if the item were moved in the SQL dataprovider. That seemed an acceptable trade off to avoid the complexity of assembling paths from ParentID values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.