"The value of a man should be seen in what he gives and not in what he is able to receive"

― Albert Einstein ―

Adding Email Column in Recent Workflow History report of Sitecore Powershell Extensions Module

If you are using Federated Authentication in Sitecore, you probably have noticed that user IDs of all AD users have random numbers in the IDs and you almost have to put an investigator cap on to find out the user if you click on the item. The DefaultExternalUserBuilder class in Sitecore creates a random user name of all external users. (Click here for more details). There are some instructions out there that you can use to customize the processor to use your own logic for user Ids. However, If you are using the Sitecore Powershell module and in need of a column or email of the user on the report then you can simply edit the Powershell script to add the desired column.

I will be adding a column to a Recent Workflow History report.

Go to Recent Workflow History located under System>Modules>

Click on the report and then in the scripting field, add the below-highlighted lines to an existing script. we are simply using  GetUser() method of System.Web.Security.Membership class to get all user membership information and that will include all properties that we need. The Get-User class only returns a few properties and does not include the Email. 


Import-Function -Name Invoke-SqlCommand

$database = Get-Database -Name "master"

$connection = [Sitecore.Configuration.Settings]::GetConnectionString($database.Name)

$historyDays = [datetime]::Now.AddDays(-14)
$parameters = @{
    "date" = $historyDays
}

$query = "SELECT DISTINCT ItemID, Language FROM WorkflowHistory WHERE Date > @date"
$itemIds = Invoke-SqlCommand -Connection $connection -Query $query -Parameters $parameters | Select-Object -ExpandProperty "ItemId"

$reportItems = @()
foreach($itemId in $itemIds) {
    if($itemId) {
        $selectedItem = Get-Item -Path "master:" -ID ([Sitecore.Data.ID]::Parse($itemId))
        $workflowEvents = $selectedItem | Get-ItemWorkflowEvent | Where-Object { $_.Date -gt $historyDays -and $_.OldState -ne $_.NewState }
     
        foreach($workflowEvent in $workflowEvents) {
     
            $previousState = $null
            $currentState = $null
            if($workflowEvent.OldState) {
                $previousState = Get-Item -Path "master:" -ID $workflowEvent.OldState
            }
         
            if($workflowEvent.NewState) {
                $currentState = Get-Item -Path "master:" -ID $workflowEvent.NewState
            }
            $userInfo = Get-User -Id $workflowEvent.User
            $user = [System.Web.Security.Membership]::GetUser($userInfo.Name)
         
            $comments = $null
            if($workflowEvent.CommentFields) {
                $comments = $workflowEvent.CommentFields["Comments"]
            }
         
            $reportItem = [pscustomobject]@{
                "Email" = "$($user.Email)"
                "User" = "$($user.UserName)"
                "Date" = $workflowEvent.Date
                "OldState" = $previousState.Name
                "NewState" = $currentState.Name
                "Comments" = $comments
                "ID" = $selectedItem.ID
                "Name" = $selectedItem.Name
                "Icon" = $selectedItem.Appearance.Icon
            }

            $reportItems += $reportItem
        }
    }
}

$reportProperties = @{
    Property = @("Icon","Name","Date","OldState","NewState","Email","User","Comments")
    Title = "Recent workflow history"
    InfoTitle = "Recent workflow history"
    InfoDescription = "View the most recent workflow history."
}

$reportItems | Show-ListView @reportProperties

Close-Window



Elastic Beanstalk Extension to Add IIS Log Custom Field

If IIS web server is not capturing the client IP address then we can easily create a custom field "X-Forwarded-For" but these manual changes will be overridden once you deploy your code using AWS Elastic Beanstalk. You can use the Elastic Beanstalk extension and Powershell to programmatically add IIS Log custom field when the code is deployed to the server. Copy and Paste the below code in a config file. (Make sure code is indented correctly or else it won't work).

The below line will get all custom field from your IIS Website and store in an array called $customFields

$customFields = Get-ItemProperty 'IIS:\Sites\Default Web Site' -Name logfile.customFields.collection

The code below will check if the "X-Forwarded-For" custom field already exists. If it does not exist then it will add a new IIS Log custom field called "X-Forwarded-For".

if([string]::IsNullOrWhiteSpace(($customFields | where-object {$_.logFieldName -eq "X-Forwarded-For"}).logFieldName)) { New-ItemProperty 'IIS:\Sites\Default Web Site' -Name logfile.customFields.collection -Value @{logFieldName='X-Forwarded-For';sourceType='RequestHeader';sourceName='X-Forwarded-For'} }

Elastic Load Balancer

OK. I need a police man on the road to handle my traffic. This highway is very busy we want the traffic to be routed into a different direction at peak time. That’s the job of the Elastic Load Balancer, policing traffic. It helps route the traffic across multiple EC2 instances. It will make sure that the servers are not overloaded with all the incoming requests and the requests are evenly distributed to all EC2 instances. This will make your application on running on EC2 instance more fault tolerance. There are different types of load balancers.

Continue Reading...

What is Elastic Compute in AWS (EC2)?

The EC2 stands for Elastic Compute. It’s a web service that helps you to create a virtual machine in the cloud. It not only reduces the time it takes to spin up a new server but also allows you to quickly scale your server up and down based on your needs. In old days, we had to go through all the process to purchase more RAM, better CPU, faster hard drive and then request the experts to upgrade the server at their earliest convenience. If all the Hardware is already there but you needed an additional virtual machine, it used to take hours or days depending on the availability of the networking team. With EC2, that’s not the case anymore, you can upgrade or downgrade the CPU, RAM or Hard drive and spin a new virtual machine using the AWS console within minutes. It also helps you to with the cost. AWS only charge you for the capacity that you consume.
Continue Reading...

What is Amazon DynamoDB?

The DynamoDB is a NoSQL database service managed by AWS. It supports all database functionalities such as storing, querying, and updating documents. When you store data in DynamoDB NoSQL database, the data is stored in a JavaScript Object Notation (JSON) format. The NoSQL has no joins and rules and that makes the NoSQL database suitable for Online Transaction Processing (OLTP). The database consists of tables, items and attributes. For example, I would like to store the names of the books that I borrowed from the public library in a NoSQL database. I will create a table (it’s a collection of data) called MyBooks and each book will contain a record called Item.
Continue Reading...

CloudWatch, CloudTrail and AWS Config

It’s very important to learn the difference between many tools available in AWS cloud. When we first learn about these tools, it seems like we are stuck in a maze. So many different routes and we do not know which one lead you to the wrong exit. To successfully utilize these tools Let’s learn the difference between CloudWatch, CloudTrail and AWS Config.
Continue Reading...

What is Simple Queue Service (SQS)

AWS Service is a service that queue messages and allows the organization to run their processes independently and send, store, and receive messages between the processes. You do not need to manage the SQS service as it will automatically scale based on the demand. There are two different types of queues.
Continue Reading...

Introduction to CloudWatch

The Amazon CloudWatch is a monitoring service that lets you monitor your AWS resources, billing, and applications in your AWS environment or resources on premises. The CloudWatch can be used to monitor any application or resources. Some of the resources that can be monitored by CloudWatch are:
Continue Reading...