Skip to content

Instantly share code, notes, and snippets.

/ConvertTo-ProperCase.ps1 Secret

Created Sep 30, 2015
Embed
What would you like to do?
#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