#requires -version 2.0 # ----------------------------------------------------------------------------- # Script: ConvertTo-TitleCase.ps1 # Author: Jeffery Hicks # http://jdhitsolutions.com/blog # Date: 12/17/2010 # Keywords: # Comments: # # ----------------------------------------------------------------------------- Function ConvertTo-TitleCase { <# .Synopsis Convert a string to title case. .Description Take a string and return a version in title case where each word is capitalized. .Parameter Text The string you wish to convert to title case. .Example PS C:\> ConvertTo-TitleCase "a tale of two cities" A Tale Of Two Cities .Notes NAME: ConvertTo-TitleCase- VERSION: 1.0 AUTHOR: Jeffery Hicks LASTEDIT: 1/10/2011 Learn more with a copy of Windows PowerShell 2.0: TFM (SAPIEN Press 2010) .Link Http://jdhitsolutions.com/blog .Link Out-String .Inputs [string] .Outputs [string] #> [cmdletBinding()] Param( [Parameter(Position=0,Mandatory=$True,ValueFromPipeline=$True)] [ValidateNotNullOrEmpty()] [string[]]$Text ) Begin { Write-Verbose -Message "Starting $($myinvocation.mycommand)" } #close Begin Process { ForEach ($string in $Text) { Write-Verbose -Message "Processing $string" #split the string into indvidual words $tmp=$string.Split() #define an array to hold modified results $out=@() foreach ($word in $tmp) { #take the first letter of each word and make it upper case, #then append the rest of the word $out+="{0}{1}" -f $word.SubString(0,1).ToUpper(),$word.substring(1) } #write the results Write-Output ($out -as [string]) } } #close process End { Write-Verbose -Message "Ending $($myinvocation.mycommand)" } #close End } #end Function