Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#requires -Version 2
This function is used to give strings their appropriate capitilization
This function takes a string as an input and capitilizes every word in the string.
Once the capitilization is complete, it will return a string object
Invoke-Capitalization -InputString 'SomE RANDom STRING to paRSe'
'SomE RANDom STRING to paRSe' | Invoke-Capitalization
This function takes a string as input
This function outputs a string
Created by: Josh Rickard
Created Date: 10-05-2015
Version: 1.0
This function is used to capitalize strings
function Invoke-Capitalization
[CmdletBinding(SupportsShouldProcess = $true,
HelpUri = '')]
# InputString help description
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
Position = 0)]
$result = @()
Write-Debug -Message "Processing $InputString"
#Process: Splitting InputString by space delimiter
#Process: Making sure that entire string is lowercase
#Reason: When using Get-Culture, if inputstring has all capital word,
#it will remain capital
$capitalArray = ($InputString.ToLower()).Split(' ')
#Process: Processing all words in array and setting them to TitleCase
foreach ($word in $capitalArray)
$result += (Get-Culture).TextInfo.ToTitleCase($word)
#returning entire array as string
return [string]$result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment