Monday 4 June 2012

Migrating FBA' User from MOSS 2007 to SP 2010


I remembered writing a power shell script to migrate forma based authentication user to claim based while working in one of the MOSS 2007 to SP 2010 migration project. I also shared the power shell script in one of the blog. But next time when I required it, I could not find it easily. So now it's time I realize to start my blog. Here I am documenting and sharing some code.

Here is the original post. (Yes my name is Anu too)
Jasper's Blog

The easy way is a simple Powershell script:

$w = Get-SPWebApplication(“url”)
$w.MigrateUsers(true)

But this script seems to have a hard coded limit to the number of users it handles or sometimes does not work. I had more then 5k users in my database, which resulted in not all users being converted. When you need to convert more, I has provided a Powershell script which will do this:

[System.Reflection.Assembly]::LoadWithPartialName(“System.Web”) | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”) | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint.Administration”) | Out-Null
$spFarm = [Microsoft.SharePoint.Administration.SPfarm]::Local
$site = New-Object Microsoft.SharePoint.SPSite(“yoursitename”);
$site.RootWeb.SiteUsers | ForEach-Object {
$name = $_.LoginName
#Write-Host $name
if($name.StartsWith(“providername:”))
Write-Host $name
$newName = $name.Replace(“providername:”, “i:0#.f|providername|”)
Write-Host $newName
$spFarm.MigrateUserAccount($name, $newName, $False)
Write-Host “Migrated User:”
}
}
$site.Dispose()

This script uses the MigrateUserAccount command to convert a single user, and loops through all users which have not yet been converted. You can tell by the format of the username; old 2007 users will be in the format ´providername:username´, new ones will look like ´i:0#.f|providername|username´.

 

No comments:

Post a Comment