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.

?View Code POWERSHELL
function ToProperCase ([String]$in)
{
 $in = $in.Tolower()
 $textInfo = [System.Threading.Thread]::CurrentThread.CurrentCulture.TextInfo  
 return $textInfo.ToTitleCase($in)
}

Example of use

?View Code POWERSHELL
$Title = "ITNOTE DOT NET"
$Title = ToProperCase($Title)

Returns:

Itnotes Dot Net

Complete Script

?View Code POWERSHELL
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)
Share and Enjoy:
  • Print
  • Digg
  • Reddit
  • StumbleUpon
  • Twitter
  • LinkedIn
  • Facebook

Tags: , ,

Monday, March 1st, 2010 Identity Management, Powershell

Leave a Reply