Migrate Users Permissions from SharePoint 2007 FBA site to SharePoint 2010 FBA site

When a SharePoint 2007 FBA site is converted to SharePoint 2010 FBA site, all the FBA users and permissions are no longer functional because the users names are different format in the new SharePoint 2010 FBA site.

One way to migrate the users/permissions is to use the following method

 $w = Get-SPWebApplication “http://site_url/” 

However this method doesn’t convert the groups (roles) correctly. the groups in SharePoint 2010 claim based FBA web application starts with “c:0-.f|…”, but the above conversion will make them start with “i:0#.f|…”

Jared created some PowerShell command and it solves the problem (you will use the code below instead of the code above)

$siteUrl = "http://site_url"
$mpName = "membership_provider_name";
$rpName = "role_provider_name";
$spFarm = [Microsoft.SharePoint.Administration.SPfarm]::Local;
$site = New-Object Microsoft.SharePoint.SPSite("$siteUrl");
$mpSearch = "$mpName" + ":";
$rpSearch = "$rpName" + ":";

$site.RootWeb.SiteUsers | ForEach-Object {
$name = $_.LoginName.ToLower();

if ($name.StartsWith("$mpSearch"))
$newName = $name.Replace("$mpSearch", “i:0#.f|$mpName|”);
"Migrating User: $name to $newName";
$spFarm.MigrateUserAccount($name, $newName, $False);
if ($name.StartsWith("$rpSearch"))
$newName = $name.Replace("$rpSearch", “c:0-.f|$rpName|”);
"Migrating Role: $name to $newName";
$spFarm.MigrateUserAccount($name, $newName, $False);

Read More