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
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:
- We are using Sitecore Dependency Injection to resolve the ResourceLoader dependency.
- The two paths passed to the constructor are visible in ShowConfig.aspx.
- 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.
- 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.