Adding users to SharePoint sites that are Active Directory users is a common task, however I couldn’t find much when I needed to get claims based FBA users added. I found out that the trick is to prefix users with the membership provider name.

i.e. corporate/admin may become i:0#.f|myMembership|admin

Putting Powershell to use I was able to loop through all site collections, add the user, then assign the user to the appropriate group.

 

$fbausers = "i:0#.f|myMembership|user1_i:0#.f|myMembership|user2".Split("{_}")




$SPWebApp = Get-SPWebApplication "http://mysitecol"

foreach ($SPSite in $SPWebApp.Sites)
{
    if ($SPSite -ne $null)
    {
        $web = $SPSite.RootWeb

        foreach ($fbauser in $fbausers){

            #Adjust group name
            $userObject = $web.EnsureUser($fbauser)
            $group = $web.SiteGroups["$($web.Title) Members"]
            $group.AddUser($userObject)
        }

        #SETTING SITE ADMIN - Set-SPSite -Identity $SPSite.url -SecondaryOwnerAlias "i:0#.f|myMembership|myowner" -OwnerAlias "i:0#.f|myMembership|myownertwo"
        $SPSite.Dispose()
    }
}

No Comments

There are no comments related to this article.