PowerShell – ProperCase Function
Change any case to Proper Case (‘ITNOTES DoT net’ to ‘Itnotes Dot Net’):
This is very useful for us during scripted user creations when the usernames and such from the source were in random cases. This script could also be useful with auto user provisioning with ILM from another datasource, we currently us a VBScript that is much longer.
This script basically converts everything to lowercase the capitalizes the first letter of each word.
function ToProperCase ([String]$in) { $in = $in.Tolower() $textInfo = [System.Threading.Thread]::CurrentThread.CurrentCulture.TextInfo return $textInfo.ToTitleCase($in) } |
Example of use
$Title = "ITNOTE DOT NET" $Title = ToProperCase($Title) |
Returns:
Itnotes Dot Net
Complete Script
function ToProperCase ([String]$in) { $in = $in.Tolower() $textInfo = [System.Threading.Thread]::CurrentThread.CurrentCulture.TextInfo return $textInfo.ToTitleCase($in) $Title = "ITNOTE DOT NET" $Title = ToProperCase($Title) |
