Skip to content

Instantly share code, notes, and snippets.

Created September 30, 2015 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/74f3bbcec719a9e0a75e to your computer and use it in GitHub Desktop.
Save anonymous/74f3bbcec719a9e0a75e to your computer and use it in GitHub Desktop.
#Requires -Version 2.0
<#
.SYNOPSIS
Capitalize the first letter of each word in a string of text and converts remaining letters in each word to lower case.
.DESCRIPTION
The cmdlet converts the string input to lower case and then uses Get-Culture and TextInfo.ToTitleCase to convert the first letter of each word
to upper case. The lower case is required to ensure that only the first letter is capitalized.
.PARAMETER Text
The text string to be converted.
.EXAMPLE
C:\PS> 'ThE wINDOWS PowerShell TFM book CONTEST aNd GiVeAwAy' | Capitalize-FirstLetterOfEachWord
The Windows Powershell Tfm Book Contest And Giveaway
.EXAMPLE
C:\PS> Capitalize-FirstLetterOfEachWord 'ThE wINDOWS PowerShell TFM book CONTEST aNd GiVeAwAy'
The Windows Powershell Tfm Book Contest And Giveaway
.INPUTS
System.String
.OUTPUTS
System.String
.NOTES
Author: David Mellors
Website: http://www.wahooga.com
Date: 30/09/15
#>
[CmdLetBinding()]
Param(
[Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true)]
[String] $Text
)
PROCESS {
(Get-Culture).TextInfo.ToTitleCase($Text.ToLower());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment