Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Function Format-StringToTitleCase {
<#
.Description
Capitalizes the first letter of each word in a string of text and converts the remaining letters in each word to lower case.
.Parameter Text
Sentence or string of text.
.Example
Pipe text to Format-StringtoTitleCase
'THIS IS,A tesT','ThE wINDOWS PowerShell TFM book CONTEST aNd GiVeAwAy' | Format-StringtoTitleCase
.Example
Pass an array os strings to Format-StringtoTitleCase
Format-StringtoTitleCase -Text 'THIS IS,A tesT','ThE wINDOWS PowerShell TFM book CONTEST aNd GiVeAwAy'
.Notes
Author: Jeff Buenting
Date: September 23, 2015
.Link
http://mikefrobbins.com/2015/09/23/windows-powershell-tfm-book-contest-and-giveaway/
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True, ValueFromPipeLine=$True)]
[String[]]$Text
)
Process {
Foreach ( $T in $Text ) {
Write-Verbose "Processing: $T"
# ---- Convert text to lowercase and then using the ToTitleCase Method from System.Globalization.Textinfo class (Get-Culture)
Write-OutPut (Get-Culture).textinfo.totitlecase( $T.ToLower() )
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.