Announcing the Winner of the PowerShell TFM Book Contest

Two weeks ago, I started a PowerShell contest which required the participants to convert a string of text to title case. I didn't specifically say title case but I explained that the first letter of each word should be converted to upper case and all remaining letters in each word should be converted to lower case. This was because a search on how to convert to title case with PowerShell gave away a good portion of the answer.

There were a total of 22 entries in the contest and all of them were submitted as a secret gist as stated in the requirements for the contest. A link to each entry can be found in the comments of my Windows PowerShell TFM Book Contest and Giveaway blog article. Overall, I would rate all of the submissions as good or better although some did a lot more work than was required to accomplish the task.

I went through each entry, evaluated it, and thoroughly tested each one. Based on the results that I found, I chose Jeff Buenting's entry as the winner:

 1Function Format-StringToTitleCase {
 2
 3<#
 4    .Description
 5        Capitalizes the first letter of each word in a string of text and converts the remaining letters in each word to lower case.
 6
 7    .Parameter Text
 8        Sentence or string of text.
 9
10    .Example
11        Pipe text to Format-StringtoTitleCase
12
13        'THIS IS,A tesT','ThE wINDOWS PowerShell TFM book CONTEST aNd GiVeAwAy' | Format-StringtoTitleCase
14
15    .Example
16        Pass an array os strings to Format-StringtoTitleCase
17
18        Format-StringtoTitleCase -Text 'THIS IS,A tesT','ThE wINDOWS PowerShell TFM book CONTEST aNd GiVeAwAy'
19
20    .Notes
21        Author: Jeff Buenting
22        Date: September 23, 2015
23
24    .Link
25        http://mikefrobbins.com/2015/09/23/windows-powershell-tfm-book-contest-and-giveaway/
26#>
27
28    [CmdletBinding()]
29    Param (
30        [Parameter(Mandatory=$True, ValueFromPipeLine=$True)]
31        [String[]]$Text
32    )
33
34    Process {
35        Foreach ( $T in $Text ) {
36            Write-Verbose "Processing: $T"
37
38            # ---- Convert text to lowercase and then using the ToTitleCase Method from System.Globalization.Textinfo class (Get-Culture)
39            Write-OutPut (Get-Culture).textinfo.totitlecase( $T.ToLower() )
40        }
41    }
42}

His entry used a function with a Verb-Noun name, an approved verb, singular noun, and a pascal cased name. One thing that was missing from Jeff's entry was a Requires statement to tell me what version was required by his function, but none of the entries were perfect. His entry included comment based help, although it was missing a synopsis which I typically include. It included both pipeline and parameter input along with making the parameter mandatory. I also like that Jeff went the extra mile and included support for multiple strings of text instead of just one string of text. That added a very small amount of unnecessary complexity but overall his entry was simple, clear, and concise.

There were a number of entries that didn't use the Get-Culture cmdlet to accomplish the task which created a lot of unnecessary complexity. Some of those entries also added things like an extra space at the end of the string which showed up in the Pester tests that I ran against each entry:

contest-winner1a.jpg

Before I had even thought about using this task for a contest, I had written a simple solution for it. My original solution didn't of course include comment based help among other things, but it is unique and I was actually surprised that no one else submitted a similar solution:

1filter ConvertTo-MrTitleCase {(Get-Culture).TextInfo.ToTitleCase($_.ToLower())}

contest-winner2a.jpg

I decided to take Jeff's entry and update it with what I thought it was missing along with a few things that are just personal preferences of mine:

 1#Requires -Version 3.0
 2function ConvertTo-MrTitleCase {
 3
 4<#
 5.SYNOPSIS
 6    Capitalizes the first letter of each word in a string of text and converts the remaining letters in each word to lower case.
 7
 8.DESCRIPTION
 9    ConvertTo-MrTitleCase is an advanced function that converts each word in one or more strings of text to title case.
10
11.PARAMETER Text
12    One or more sentences or strings of text.
13
14.EXAMPLE
15    'THIS IS,A tesT', 'ThE wINDOWS PowerShell TFM book CONTEST aNd GiVeAwAy' | ConvertTo-MrTitleCase
16
17.EXAMPLE
18    ConvertTo-MrTitleCase -Text 'THIS IS,A tesT', 'ThE wINDOWS PowerShell TFM book CONTEST aNd GiVeAwAy'
19
20.INPUTS
21    String
22
23.OUTPUTS
24    String
25#>
26
27    [CmdletBinding()]
28    param (
29        [Parameter(Mandatory,
30                   ValueFromPipeline)]
31        [String[]]$Text
32    )
33
34    PROCESS {
35        foreach ($t in $Text) {
36            Write-Verbose -Message "Processing: $t"
37            Write-Output (Get-Culture).TextInfo.ToTitleCase($t.ToLower())
38        }
39    }
40}

Congratulations to Jeff and thanks to everyone who took the time to participate in this contest.

µ