Based on your question I think you need something that will require a bit more finesse, so here's my attempt - It will only show renderings that have no datasource, but need them
function Test-DataSourceRequired {
[CmdletBinding()]
param([Sitecore.Data.ID]$RenderingId)
$rendering = Get-Item master: -ID $RenderingId
# if data source location and data source template are empty then it's ok for the rendering to have no data source defined
return -not [string]::IsNullOrEmpty($rendering."Datasource Location") -or -not [string]::IsNullOrEmpty($rendering."Datasource Template")
}
function Test-ContainRenderingsWithoutDataSources {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[Sitecore.Data.Items.Item]$Item)
#Test Versioned Layout
$BrokenRendering = Get-Rendering -Item $Item -FinalLayout | Where-Object { ($_.Datasource -eq "") -and (Test-DataSourceRequired $_.ItemID) }
$BrokenRendering | %{ Write-Host "$($Item.Paths.Path) - '$((Get-Item master: -ID $_.ItemId).Name)' has no datasource" -ForegroundColor Red }
}
Get-Item -Path master:\content\Home | Test-ContainRenderingsWithoutDataSources
In this case I'm checking whether the rendering that we are inspecting (that has no datasource specified) actually requires one. By requires I understand that the rendering has a value in "DataSource Location" and "DataSource Template". that filters out false positives where renderings that don't need datasource would be shown.
You can pipe multiple items into the cmdlet as well like:
Get-ChildItem -Path master:\content\Home -Recurse | Test-ContainRenderingsWithoutDataSources
Sample output:
