David Peterson bio photo

David Peterson

David is a Sitecore Architect with ATP World Tour, founder of the Philadelphia Sitecore Users Group and Technical Sitecore MVP. Often reminiscing of his days as a Sysop and being Elite.

Email Twitter LinkedIn Github

With a multisite Sitecore instance in Sitecore 8,1u3, we were in need of having site-specific renderings, some of which shared controller names across sites. While integrating on instance into another, scripting was required to update Sitecore controller rendering references to use their fully qualified assembly names instead of the more simple approach. The following script was used to perform this update.

The script assumes controller renderings reside in their site’s area, as well as, having a default namespace preceding the area reference in the namespace.

function Update-ControllerRenderingsWithNamespace {
    $startLocation = 'master:\sitecore\layout\Renderings'
    Set-Location $startLocation
    Get-ChildItem -recurse | where-object { $_.TemplateName -match 'Controller rendering' -and !($_."Controller" -match ', $defaultNamespace') } | foreach {
        $controller = $_."Controller".Trim()
        $controllerValue = "$($defaultNamespace).Areas.$($siteName).Controllers.$($controller)Controller, $($defaultNamespace)"
        Write-Host "Found" $_.FullPath
        Write-Host "Updaing to: " $controllerValue
        $_."Controller" = $controllerValue