Friday, October 29, 2010

Handy powershell script for "Data is Null" error

Earlier I blogged about a "Data is Null" error breaking the search in SharePoint 2010. http://jcapka.blogspot.com/2010/08/nasty-data-is-null-error-in-sharepoint.html

Seems that while we were on the right path, the cause of the problem was just a little off.  When creating a new site group through code, the parameter that was causing the problem is not the "default user" parameter but rather the "description" parameter. When the description is null, the search breaks.

Microsoft has a fix (http://support.microsoft.com/kb/2323206) on their website for updating the null description values and while the fix is perfectly valid, it is code and you may not be allowed to run this code in all cases. (Try getting approval to run a console app on a production machine).  So here is a small powershell script to help you fix the NULL descriptions.

Function UpdateEmptyDescriptions($siteUrl)
{
        $site =  Get-SPSite $siteUrl
        
        $needupdate = $site.RootWeb.SiteGroups  | Where-Object {$_.Description -eq $NULL} 
        
        If($needupdate)
        {
            Write-Host "Site Groups that are being updated"
            Write-Output $needupdate | Format-Table Name
            $needupdate | ForEach-Object{$_.Description = $_.Name}
            $site.RootWeb.SiteGroups | % {$_.Update()}
        }
        Else
        {
            Write-Host "No Update Needed"
        }
}

UpdateEmptyDescriptions("http://mysite.local")

2 comments:

Damien said...
This comment has been removed by the author.
Damien said...

I have developping a little Windows Form to do the job.
http://sp2010fixgroups.codeplex.com