Configuring FBA (SQL or LDAP) for SP 2010 and SP 2013


Script allows an IT admin to configure LDAP or SQL based FBA on SharePoint 2010/2013 web applications i.e. it makes all the changes in web.config files of Central Admin, STS and web applications on all the Servers automatically minimizing the possibility of human error and drastically reducing the time and effort. It also puts in place basic checks like SQL/LDAP connectivity checks, duplicates, web application eligibility for FBA. Most important it takes the backup of each file before modifying anything providing a kind of failback mechanism in case of issues


Normally configuring FBA in SharePoint involves manual entry of various kinds in web.config files of CA, STS and target web application on all the servers in the farm, resulting in higher probability of human induced errors and subsequently increased time and effort.


Script makes extensive use of PowerShell cmdlets exposed in SharePoint PowerShell and System.Xml.XmlDocument class for modifying config files.

Here are some code snippets for your references.

The sample scripts are not supported under any Microsoft standard support  
program or service. The sample scripts are provided AS IS without warranty   
of any kind. Microsoft further disclaims all implied warranties including,   
without limitation, any implied warranties of merchantability or of fitness for  
a particular purpose. The entire risk arising out of the use or performance of   
the sample scripts and documentation remains with you. In no event shall  
Microsoft, its authors, or anyone else involved in the creation, production, or  
delivery of the scripts be liable for any damages whatsoever (including,  
without limitation, damages for loss of business profits, business interruption,  
loss of business information, or other pecuniary loss) arising out of the use  
of or inability to use the sample scripts or documentation, even if Microsoft  
has been advised of the possibility of such damages  
#Author: Yash Goel, Technical Support Lead, Microsoft Corporation 
$farm = get-spfarm 
$key = "HKLM:\software\microsoft\shared tools\web server extensions\" + $farm.BuildVersion.Major + ".0" 
$loc = (Get-ItemProperty -path $key).location 
$ca = 0 
$changes = $false 
$wa = read-host "Enter Web Application URL" 
$webapplication = Get-SPWebApplication $wa 
write-host "Web App is not claims aware. Please convert the web app to claims first" 
Write-host "following zones found for the web application" 
write-host "================" 
write-host "Zones" 
write-host "================" 
$zonecount = $webapplication.iissettings.keys.count-1 
$zone = read-host "press number corresponding to zone you want to configure(0-"$zonecount")" 
if(($zone -lt 0) -or ($zone -gt $zonecount)) { write-host "Invalid Zone! Please re-enter" } 
}while(($zone -lt 0) -or ($zone -gt $zonecount)) 
$pathwa = $webapplication.IisSettings[$zone].path.fullname 
$ca = Get-SPWebApplication -IncludeCentralAdministration | ?{$_.displayname -eq “SharePoint Central Administration v4"} 
$pathca = $ca.IisSettings[0].Path 
$pathsts = $loc +  "WebServices\SecurityToken" 
$type = read-host "Type of FBA (LDAP or SQL) " 
if($type -ne "sql") 
  if ($type -ne "ldap") 
     write-host "Incorrect FBA type" 
#==================================== DB TEST ============================================================== 
 function dbtest($SQLServer1, $sqldb1, $userid1, $pwd, $sqlauth) 
   $sqlauth = !$sqlauth 
   $conn = New-Object System.Data.SqlClient.SqlConnection 
   $conn.ConnectionString = "Data Source=" + $SQLServer1+ ";Initial Catalog=" + $sqldb1 + ";User ID=" + $userid1 +";Password=" + $pwd + ";Integrated Security=" + $sqlauth +";" 
   try{ $ 
   catch { [System.Exception] 
   write-host -ForegroundColor Red $_.Exception.Message 
   write-host "Connectivity test failed ! Re-enter DB details" 
   return $false  

Examples :

Copy the script on one of the SharePoint Servers in the farm where you want to configure the FBA.

Run the script and it will ask for the following parameters

  1. Web application URL.
  2. Select the Zone of the web application.
  3. Type of FBA ( SQL or LDAP)
  4. RoleManager and Membership information needed for configuring requested LDAP.




Additional Resources

[Technical Resources:]