Saturday, January 27, 2018

Sitecore 9 Installation Guide

Step by step Sitecore 9 Update 1 Installation guide:

As a part of my Sitecore knowledge Upgradation, I wanted to install Sitecore9 on my local system. Here are the steps that I followed the process.
In order to install the update, you can follow any of the below guides from Sitecore Architects.

Note: I followed the same steps as in the link - http://www.flux-digital.com/blog/install-sitecore-9-update-1-4-simple-steps/ and it works fine.
The below guide covers the complete installation following the same process, some of the issues faced by it and how it can be resolved. In addition, the log file has been attached as well with this guide to give a glimpse of the events and for tracking purpose.
 
PREREQUISITES:
Source: Sitecore 9 Update 1 Installation Guide
IIS Requirement – IIS10.0/IIS8.5
OS Requirement - Windows Server 2016, Windows Server 2012 R2 (64-bit), Windows 10 (32/64-bit), Windows 8.1 (32/64-bit)
.Net Framework Requirement - .NET Framework 4.6.2 or later.
JRE Requirement – Latest version
Visual Studio Requirement - Microsoft Visual Studio 2015 or later.
Database Requirement - Microsoft SQL Server 2016 SP1, Microsoft SQL Server 2014 SP2
Search Indexing Requirement - Solr 6.6.2(for Sitecore 9 update 0 – Solr 6.6.1), Azure Search
Hardware Requirement - 4 core processor, 16GB of RAM
  


Powershell script for installation:
Everyone needs automation in the installation process including me. So, our Sitecore Architects wrote the PowerShell Script to automate the installation process which makes our work easier. (But, if you are a person who feels that a mere installation is not enough and sheer understanding of the whole process is required you can consider reading the below section on the process explanation.)

Assumption: Create a folder “Sitecore9\Resources” under c:\ (where I had all my resource files)
Checklist:
Check 1: When I run the first Powershell Script, I got the below error:
.\Install-Solr.ps1: File C:\Sitecore9\Install-Solr.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see
about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\Install-Solr.ps1
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

·       In order to resolve this problem, run the below command:
PS C:\Sitecore9> Set-ExecutionPolicy RemoteSigned
·       The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the
about_Execution_Policies help topic at http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A
It will ask you for the Execution policy change. Give "A" and proceed.







Check 2: Before running the script check the Admin access
PS C:\Sitecore9>[bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")
Check 3: SQL Server  sa username and password
Check 4: JRE version 1.8.0_162
Check 5:  Sitecore License file and copy to C:\Sitecore9\Resources.
Resource Files:
Download the below files and place all files under C:\Sitecore9\Resources:
2.       Sitecore 9.0.1 rev. 171219 (WDP XP0 packages).zip (https://dev.sitecore.net/~/media/8551EF0996794A7FA9FF64943B391855.ashx)
3.       After downloading Sitecore 9, unzip it.  Copy “Sitecore 9.0.1 rev. 171219 (OnPrem)_single.scwdp” and “Sitecore 9.0.1 rev. 171219 (OnPrem)_xp0xconnect.scwdp” to C:\Sitecore9\Resources.
4.       Unzip “XP0 Configuration files 9.0.1 rev. 171219.zip” and copy all the files to C:\Sitecore9\Resources.
At last the C:\Sitecore9\Resources path should look like this:



Now we are ready to run the scripts :
Step 1: Solr Installation
Since Solr was made as core requirement in Sitecore 9, we need to install solr in SSL mode(https). We are using Jeremy Davis Powershell script for installing the solr. In this script we need to mention the below:
    $solrVersion = "6.6.2", -- Version of Solr. We use 6.6.2 for Sitecore 9 update1
    $installFolder = "C:\Sitecore9\Solr", -  Here the solr will get installed
    $solrPort = "8983", - Default solr port
    $solrHost = "sc9solr", - Solr host name
    $solrSSL = $true, -- This should be true, we need to run solr in SSL mode(https)
    $nssmVersion = "2.24", -- NSSM version which we used to install solr as a service(don’t change it)
    $JREVersion = "1.8.0_162" --  JRE version in your local system ( run this command in cmd to find the version : java -XshowSettings:properties -version)
  $JREPath = "C:\Program Files (x86)\Java\jre1.8.0_162" (in the above command you can get the JRE path)
$downloadFolder = " C:\Sitecore9\Resources" – (The path where we downloaded and copied solr zip)

·       Copy the below script as “Install-Solr.ps1” in C:\Sitecore9
·       Open Powershell and run the script
PS C:\Windows\system32>cd \
PS C:\>cd Sitecore9
PS C:\Sitecore9> .\Install-Solr.ps1

The Solr has been installed successfully and you will see the Solr running in SSL Mode(https).


Step 2:  Install Sitecore Install Framework(SIF)
Here we are gonna use PowerShell script wrote by Flux-digital to install SIF.
·       Copy the below script as “Install-SIF.ps1” in C:\Sitecore9
·       Don’t change anything in this script and run in PowerShell.


Step 3:  Install Sitecore 9
·       Copy the below script as “Install-Sitecore9.ps1” in C:\Sitecore9
·       Define the below parameters in the script
$prefix = "sc91" – Instance name prefix
$PSScriptRoot = “C:\Sitecore9\Resources”  -- Path of all resource file
$XConnectCollectionService = "$prefix.xconnect" --  Xconnect name “sc91.xconnect”
$sitecoreSiteName = "$prefix.local" – Instance name “sc91.local”
$SolrUrl = https://sc9solr:8983/solr  -- Solr URL
$SolrRoot = "C:\Sitecore9\solr-6.6.2"  --  Solr Root Path
$SolrService = "solr-6.6.2"  -- Solr Service name
$SqlServer = "\"  -- SQL Server Data source name
$SqlAdminUser = "sa"  - sa username
$SqlAdminPassword = "****"   -- Sa password

·       Run the script and it will take nearly 10mins to execute each step.
·, At last, you can see that the Sitecore instance is up and running.



The below log files of Sitecore 9 Installation:

Saturday, January 20, 2018

Sitecore Powershell :: Reporting 'used image items with empty Alt field' using Alt tag Action

My client came up with a requirement to get the list of Media items with empty Alt field. In our existing Powershell package, we already have such reports.

But, when the requirement got refined to get the list of Used Media items with empty Alt Field (Because we have junk of media items which were unused) there were no options.
As a result,  I created the below scripts to get Used media items with Empty Alt field.
Create a Script under the path (/sitecore/system/Modules/PowerShell/Script Library/Content Reports/Reports/Media Audit/Used Image items with empty Alt field)




function HasReference {
    param(
        $Item
    )
    
    $linkDb = [Sitecore.Globals]::LinkDatabase
    $linkDb.GetReferrerCount($Item) -gt 0
}

function Get-MediaItemWithNoReference {
    $items = Get-ChildItem -Path "master:\sitecore\media library" -Recurse
 | Where-Object { $_.TemplateID -ne [Sitecore.TemplateIDs]::MediaFolder }
    
    foreach($item in $items) {
        if((HasReference($item))) {
   if($item."Alt" -eq '') {
            $item
        }
      }
    }
}

$items = Get-MediaItemWithNoReference

if($items.Count -eq 0) {
    Show-Alert "There are no used media items."
} else {
    $props = @{
        InfoTitle = $PSScript.Name
        InfoDescription = "Lists used media items that are not linked from other items."
        PageSize = 25
        Title = $PSScript.Name
    }
    
    $items |
        Show-ListView @props -Property @{Label="Name"; Expression={$_.DisplayName} },
            @{Label="Updated"; Expression={$_.__Updated} },
            @{Label="Updated by"; Expression={$_."__Updated by"} },
            @{Label="Created"; Expression={$_.__Created} },
            @{Label="Created by"; Expression={$_."__Created by"} },
            @{Label="Path"; Expression={$_.ItemPath} }
}
Close-Window


After running the script, I extracted the report with empty Alt tags.
But then I thought how they will be able input those bulk data from the report.
So, instead of opening each item, I came up with an idea to give them the Alt field against each media item. Hence, I created the Alt Tag Action under Item Ribbon.
(/sitecore/system/Modules/PowerShell/Script Library/Platform/Internal/List View/Ribbon/Item/Alt Tag)



foreach($Item in $selectedData)
{
    
$mediaItem = [Sitecore.Data.Items.MediaItem]$item;
$alt = $mediaItem.Alt;
$result = Read-Variable -Parameters `
   @{ Name = "alt"; Title = "Alt Tag";  Columns = 6 }   `
   -Description "Edit alt tag of '$($Item.DisplayName)'" `
   -Title "$($Item.DisplayName)" -Icon "Applications/16x16/photo_scenery.png"
                -Width 400 -Height 470 -OkButtonName "Change"
                -CancelButtonName "Cancel" -ShowHints;
  if ($result -eq "ok") {
  $Item.Editing.BeginEdit()
    $Item.Fields["Alt"].Value = $alt
    $Item.Editing.EndEdit()

 }
}


But this action was applicable for all the items, now what to do ??
Simple, restrict the rules only for Media items as below and it’s done ️.




Run the script now.







Select the media Item and Click Alt Tag Action.




Click change and open the Media item for the verifying the Input.



Download the Sitecore Package: Alt Tag Powershell Package

Thursday, January 11, 2018

Sitecore Powershell :: Redirect URL List


I wanted to make my hand dirty by exploring more on Sitecore Powershell, So I installed “Sitecore PowerShell Extensions-4.7 for Sitecore 8” Package and started looking into the ISE and console with existing Scripts. Suddenly something came to my mind. And, its the idea to list the Redirect URL in our site (Which may be huge in other sites).

Perquisites:   Redirect Module should have been used on your site.
Process:
Firstly, I created a new Redirect Powershell Script Module under Script Library.
And then, I created a Toolbox Script Library and then Redirect URL List Script.


In Scripting field, I wrote the below scripts:
# Get all the items recursively where the TemplateName equals "Redirect Url".
Get-ChildItem -Path master:\sitecore\system\Modules -Recurse | 
Where-Object { $_.TemplateName -match "Redirect Url"  } |
    Show-ListView -Property @{Label="Name"; Expression={ $_.DisplayName } },
  @{Label="Requested Url"; Expression={ $_.Fields["Requested Url"]} },
  @{Label="Response Status Code"; 
Expression={ $_.Database.GetItem($_.Fields["Response Status Code"]).Name} },
  @{Label="Redirect To Item"; 
Expression={ [Sitecore.Links.LinkManager]::GetItemUrl($_.Database.GetItem($_.Fields["Redirect To Item"]))} },
  @{Label="Redirect To Url"; Expression={ $_.Fields["Redirect To Url"]} }  `
        -Title "Redirect URL List"
        
Close-Window


After the completion of the Creation process, It should be listed in Powershell Toolbox as below.


Below is the result obtained on the click of Script created,:


Explanation:
This will extract all the items with the template name “Redirect URL”. In the List view property, the fields have been bound. To get the Redirect Item, I used Linkmanager that gives the Item URL.

Download the Sitecore Package: Redirect URL list Package