Skip to main content

Posts

Showing posts with the label powershell

Sitecore Powershell Script to Update Datasource Path In Final Rendering

Sitecore Powershell Script to Update Datasource Path In Final Rendering  In project, there was a requirement to update datasource for specific rendering so to update the rendering datasource I wrote below PowerShell script.   Function Change-RenderingDatasourceInAllPages{ Param( [Parameter(Mandatory=$true)] [String]$PagesRoot, [Parameter(Mandatory=$true)] [String]$Placeholder, [Parameter(Mandatory=$true)] [String]$DataSourcePath, [Parameter(Mandatory=$true)] [String]$ItemId ) $pages = @(get-item $PagesRoot) $pages += @(get-childitem -Path $PagesRoot -Recurse) $defaultLayout = Get-LayoutDevice "Default" foreach($page in $pages) { Get-Rendering -Item $page -Device $defaultLayout -FinalLayout -Placeholder $Placeholder | ForEach { if($_.ItemID -eq $ItemId) { $_.Datasource=$DataSourcePath Set-Rendering -Item $page -Instance $_ -FinalLayout:$True