I set up SharePoint 2013 with FBA users (SQL). I'd like to know if it's possible to create new users using PowerShell script ?

What I tried but did not work :

[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", "C:\inetpub\wwwroot\wss\VirtualDirectories\mysite\web.config")

But the last command only shows me the default AspnetSqlMembershipProvider ... and not my custom one (web.config is configured with a custom Membership provider, and FBA SQL Authentication is working).

  • did my answer help you at all? – jpollar Jun 25 '15 at 14:17


I found a source that may help you immensely. The following link walks you through how to use a PowerShell script to import a list of users from Excel and create them for FBA.

Importing and Exporting Data in Extranet Collaboration Manager (ExCM) 2010

You can also download the PowerShell source code from this link.

It looks like the code creating the user account is as follows.

# Import user
$status = [System.Web.Security.MembershipCreateStatus]::Success
$extranetUser = $membershipProvider.CreateUser($username, $password, $email, $passwordQuestion, $passwordAnswer, $true, $null, [ref]$status)

You may need to modify the code to fit your needs, but it should get you pointed in the right direction. Let me know if you need further assistance. I'm eager to help.


  • Thanks for your help. I apologize for the delay, I've been busy a lot. This must work and I'm gonna give a try soon ! Thanks @jpollar – Nico Jun 28 '15 at 16:22
  • Let me know if you have trouble implementing it. – jpollar Jun 28 '15 at 20:02
  • Ok, I have problems while implementing it. When I execute this code $membershipProviderName = "SQLMembership" $membershipProvider = [System.Web.Security.Membership]::Providers[$membershipProviderName] When I want to use $membershipProvider nothing happens. I tried a full execution, but user was not created. I have doubts on LoadingAssembly at the beginning, maybe it comes from that ? – Nico Jun 29 '15 at 12:10
  • I only get a "Cannot invoke null parameter" on the line $membershipProvider.CreateUser(...), any ideas ? – Nico Jun 29 '15 at 12:17
  • I guess this is because [System.Web.Security.Membership]::Providers only returns the default provider ... And not the one I newly created whereas I can see it with Get-SPAuthenticationProvider and from IIS – Nico Jun 29 '15 at 12:58

I've just start looking into creating FBA users through PowerShell, I found that if I used the SharePoint Management Shell the only membership provider that was returned was the default provider, if I ran the same commands in an elevated PowerShell window then I got all of the membership providers including my custom one.

So do not use the SharePoint Management Shell just a regular PowerShell window.


I solved the issue of not being able to set the CurrentDomain APP_CONFIG_FILE. Which was why his original commands did not work. When PowerShell loads the default sql database is already loaded in the APP_CONFIG_FILE. When you use SetData it doesn't overwrite, but adds it as a second connectionString. When you look for providers only the first connectionString for default gets used. So we have to remove the first connectionString. Here is all the code that will add a user to FBA in 2013.

*You will need to change $configurationFile to reflect your directory.

*You will need to change $membershipProvider to reflect your membershipprovider name that you set in central admin->application management->Mange Web Applications -> Authentication Providers. You already know this if you set up FBA...

*You need to run as admin, and it "MAY" only work in regular 64-bit Windows PowerShell. I run it in both regular and SharePoint PowerShell though.

echo "Creating SP Users"
#Load Assemblies for SharePoint and PowerShell

#Remove the default APP_CONFIG_FILE value this allows you to get the correct Membership provider
Add-Type -AssemblyName System.Configuration
[Configuration.ConfigurationManager].GetField("s_initState", "NonPublic, Static").SetValue($null, 0)
[Configuration.ConfigurationManager].GetField("s_configSystem", "NonPublic, Static").SetValue($null, $null)
([Configuration.ConfigurationManager].Assembly.GetTypes() | where {$_.FullName -eq "System.Configuration.ClientConfigPaths"})[0].GetField("s_current", "NonPublic, Static").SetValue($null, $null)

$configurationFile = "C:\inetpub\wwwroot\wss\VirtualDirectories\80\web.config"
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $configurationFile)

$membershipProviderName = "FBAMembership"
$membershipProvider = [System.Web.Security.Membership]::Providers[$membershipProviderName]

if($membershipProvider -eq $null)
    throw "The membership provider '$membershipProviderName' could not be found."

$status = [System.Web.Security.MembershipCreateStatus]::Success
$newMember = $membershipProvider.CreateUser("dtest.user", "!Q@W#E$R%T1q2w3e4r5t", "dtest.user@mail.mil", "test", "test", $true, $null, [ref]$status)

#echo $newMember

I have looked at trying to get this to work following the extra steps suggested by Brian am having similar problems that others reported earlier on.

I ran the scripts to replace the default APP_CONFIG_FILE value. This appears to have worked because if I execute the following I get the file location and name of the membership config file I want to use:


Nonetheless setting the membership provider on the following line seems to cause problems as I can never get a value returned from $membershipProvider.

$membershipProvider = [System.Web.Security.Membership]::Providers[$membershipProviderName]

Looking further it seems like i still do not clear the default membership provider as [Configuration.ConfigurationManager]::ConnectionStrings[0]. Name still returns the default value even after running the scripts to clear this value as suggested by Brian.

I can confirm I am running from PowerShell ISE in admin level (so not SharePoint Shell).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.