A script to remove training spaces from public folder names

I am completely sick of the sight of this error:

WARNING: Object \public folder path   has been corrupted and it is in an inconsistent state. The following validation errors have occurred:
WARNING: The Name property contains leading or trailing whitespace, which must be removed.

So here’s powershell script to find and rename the offending folders. (Why exactly Outlook allows people to name them with a space at the end I DO NOT KNOW!)

$getpfcmd = "get-publicfolder -Recurse -resultsize unlimited"
invoke-expression $getpfcmd | foreach {
    if ($_.Name -ne $null -and $_.Name.substring($_.Name.length - 1,1) -eq " ")
	    write-host $_.Name
	    $newname = $_.Name.Trim()
             $pfid = $_.identity.MapiEntryId.tostring()
	    Set-PublicFolder -Identity $pfid  -Name $newname


About: Carol

I've been doing IT for 30 years, and IdM for 15. I live in Australia and build IdM solutions based on Microsoft Identity Manager. I also play the violin, but that doesn't help much with the IdM solutions.

One thought on “A script to remove training spaces from public folder names”

  1. I empathize completely 🙂 Working with Public Folders is kludgy on the best of days. I wish they would disappear but their death has been foretold too many times for me to believe it will happen soon.


Comments are closed.