Thursday, September 23, 2021

Most useful Powershell scripts for a Sitecore developer

 A Sitecore PowerShell script to check if the selected sub tree of items have the language fallback enabled and update the items to enable the language fallback accordingly

Is this not the script you are looking for? Then check this complete list of Sitecore Powershell scripts

Check if language fallback enabled on an Item

The script is used to check an item and all its descendants if the language fallback is enabled. It lists all the items for which the language fallback is not enabled.

Fallback option

The script checks the value in the field ''__Enable Item Fallback'' for each item. This field value is '1' when the language fallback is enabled.

$sourcePath = "master:/sitecore/content/Home/Site1"
$items = Get-ChildItem -Path $sourcePath -Recurse
$rootItem = Get-Item -Path $sourcePath
$items = $items + $rootItem

foreach($item in $items){
    if ($item.Fields["__Enable Item Fallback"].Value -ne "1")
    {
        Write-Host $item.ID $item.Fields["__Enable Item Fallback"].Value $item.Paths.Path
    }
}

Script for updating an item to enable language fallback###

Say if you want to enable the language fallback of an item and all its descendants, then below scripts helps you. It checks each item if the fall back is enabled, if it is not then the script would update the item to enable the language fallback and publishes it. As the __Enable Item Fallback field is a shared field, it need not to be done on each language version separately.

$sourcePath = "master:/sitecore/content/Home/Site1"
$items = Get-ChildItem -Path $sourcePath -Recurse
$rootItem = Get-Item -Path $sourcePath
$items = $items + $rootItem

foreach($item in $items){

    if ($item.Fields["__Enable Item Fallback"].Value -ne "1")
    {
        $item.Editing.BeginEdit();
        $item.Fields["__Enable Item Fallback"].Value = '1'
        $item.Editing.EndEdit();
        Write-Host $item.ID $item.Fields["__Enable Item Fallback"].Value $item.Paths.Path
    }
 
}

LanguageFallback

Hope this helps you. Please comment your thoughts.

Wednesday, September 15, 2021

How to create a login for Content author in Sitecore

 By default sitecore provides an admin user with userid ‘Admin’ and password ‘b’. However additional users can be created in sitecore by following below steps.

  1. Login to sitecore as admin in desktop mode.

  2. Go to security tools and then user manager.

  3. Click on ‘New’ button present at the top left corner.

  4. Give the Username say ‘User1’, Email Id and Password.

  5. Then click on ‘Edit’ to add Roles to this new user.

  6. Select the following roles from the below list and click on Add. This list provide the roles required for a content author.

    • Sitecore\Developer
    • Sitecore\Sitecore Client Publishing
    • Sitecore\Designer
    • Sitecore\Author
    • Sitecore\Sitecore Client Users
  7. By adding the above roles, the below list of sub roles will be automatically added.

    • Sitecore\Sitecore Client Designing
    • Sitecore\Sitecore Client Configuring
    • Sitecore\Sitecore Client Maintaining
    • Sitecore\Sitecore Client Developing
    • Sitecore\Analytics Testing
    • Sitecore\Analytics Personalization
    • Sitecore\Sitecore Client Authoring
  8. Then click Ok and Finish. We have now created a new user and then assigned the roles of a content author.