Convert SharePoint List Items to Lowercase using PowerShell


Sorry for the lack of blogging lately, it’s not that I haven’t had PLENTY of material – I just frankly haven’t had time to post anything.

However, I thought I’d share a recent function I threw together – if for no other reason than to make sure I don’t forget how I did this…

I’m currently working on a big migration from a legacy HTML website to SharePoint 2010 FIS-E. During this migration, I’ve used PowerShell a LOT to automate tasks and cleanup things. An example of something I needed to clean up is links used for top navigation. We are using a 3rd party web part for our top navigation – it is list driven.

The links in the list all work, but some were entered as lowercase, some camel-case, some with no rhyme or reason at all. I wanted consistency, and I’m sure my client would too…

I wrote a simple helper function to walk through the list and convert every item in a specified column to lowercase. Pretty easy, not much to it… Also, this could easily be modified to do other things like convert to uppercase. I just wanted lowercase. Here it is!

function Convert-SPListItemStringsToLowercase {
Param(
[string]$WebUrl,
[string]$ListName,
[string]$ColumnName
)
$web = Get-SPWeb $WebUrl                                                                    
$list = $web.Lists[$ListName]                                                                                             
$items = $list.Items                                                                                                   
	foreach ($item in $items){
		$item[$ColumnName] = $item[$ColumnName].toLower()
		$item.Update()
		$list.Update()
		}#end Foreach
	$web.Update()
	$web.Dispose()
}#end function