Skip to content

Instantly share code, notes, and snippets.

@MSAdministrator
Last active October 6, 2015 01:26
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 MSAdministrator/1b59d8a53c1494b6cee9 to your computer and use it in GitHub Desktop.
Save MSAdministrator/1b59d8a53c1494b6cee9 to your computer and use it in GitHub Desktop.
#requires -Version 2
<#
.Synopsis
This function is used to give strings their appropriate capitilization
.DESCRIPTION
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
.EXAMPLE
Invoke-Capitalization -InputString 'SomE RANDom STRING to paRSe'
.EXAMPLE
'SomE RANDom STRING to paRSe' | Invoke-Capitalization
.INPUTS
This function takes a string as input
.OUTPUTS
This function outputs a string
.NOTES
Created by: Josh Rickard
Created Date: 10-05-2015
Version: 1.0
.FUNCTIONALITY
This function is used to capitalize strings
#>
function Invoke-Capitalization
{
[CmdletBinding(SupportsShouldProcess = $true,
HelpUri = 'https://gist.github.com/MSAdministrator/1b59d8a53c1494b6cee9')]
Param
(
# InputString help description
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
Position = 0)]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[Alias('p1')]
[string]$InputString
)
Begin
{
$result = @()
}
Process
{
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)
}
}
End
{
#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