Powershell script to change the template in Sitecore

Powershell script to change the template in Sitecore

Within the Sitecore platform, a PowerShell script is a useful tool. It lets users carry out a variety of activities and automate processes within the Sitecore environment.

Sitecore is a popular content management system for creating and maintaining websites. It offers an easy-to-use interface for handling media assets, adding and modifying content, and managing the general layout of the website.

Users may automate repetitive activities in Sitecore and save time and effort by utilizing PowerShell scripts. They have the ability to create new items, updating existing items, and deleting items in bulk.

Sitecore PowerShell scripts may also be utilized to carry out sophisticated tasks like report generation, data analysis, and custom logic execution. This enables users to customize Sitecore to meet their own demands and expand its capabilities.

Users must have access to the Sitecore instance and the required permissions in order to run a PowerShell script in Sitecore.

From Sitecore Desktop-> Navigate to PowerShell ISE.

Powershell Script


Copy the script below and change the template ID. Then Click on Execute.

$targetPath = "master:/sitecore/content/Sample/Home/AA/Article 1"
$items = Get-ChildItem -Path $targetPath -Language * -Recurse
$rootItem = Get-Item -Path $targetPath
$items = $items + $rootItem
$list = [System.Collections.ArrayList]@()
function Changetemplate {
    foreach($item in $items)
    {
		#Matching Article Template
        if ($item.TemplateId -eq "{61D38571-FA0A-4D73-833B-2D11E9E08612}")	
        {	
            $item.Editing.BeginEdit();
			#Replacing Article Template to different Template
            $item.TemplateId = "{1BB66BEE-A3C2-4F8B-BDDF-BF903F3D8498}"
            $item.Editing.EndEdit();  
			Write-Host "Item id: " $item.ID  " - Item path: " $item.Paths.Path "- Template id: " $item.TemplateId			
        }
    }
}

$items = Changetemplate        
Powershell Result

The item id, item path, and template id—which are modified based on the script will be returned on the log pane.

Overall, Sitecore's PowerShell scripts are an invaluable resource for both content editors and developers. They offer a practical means of work automation and improve the Sitecore platform's functionality.


Cheers to learning and sharing!

#4

#sitecore #powershell #script #bulk #sitecoresearch #sitecoreblog #sitecorecommunity #sitecoredeveloper #sitecoremvp

要查看或添加评论,请登录

Kesavamoorthi Karthikeyan的更多文章

社区洞察

其他会员也浏览了