This project has moved and is read-only. For the latest updates, please go here.

Adding FBA users through Powershell

Aug 25, 2014 at 10:00 PM
I am trying to use powershell to create FBA users instead of entering them from the 'FBA User Management' page.

The following script adds the user to sharepoint and in the correct group, but they do not end up in the FBA aspnet membership database and therefore do not show up on the 'FBA User Management' page.

$testuser = New-SPUser -Web 'http://spportal:12345' -UserAlias 'i:0#.f|FBAMembershipProvider|JohnSmith5' -DisplayName 'John Smith5' -Email '' -Group 'Business Partners'

Any help would be greatly appreciated.

Aug 25, 2014 at 10:30 PM
It should be added to the membership database before adding it to SharePoint. I didn't find any examples of doing it in PowerShell, however you should be able to take the code from here

and convert it to PowerShell, using the New-Object cmdlet. It would probably make for a good blog post if you work it out. I'm not sure where you'd specify the membership provider though, unless you put it in machine.config.
Aug 26, 2014 at 4:15 PM
Hi Chris,

Thank you for your quick response.

I will look into this a bit, but may just end up not automating this part of my project as it may be more efficient to do it manually.

Aug 28, 2014 at 10:54 AM
Hi Eric

I have done this and it is simple enough. The key to PowerShell is that its the environment you use to run it that controls the configuration so:

This caught me on the hop as I tend to develop scripts in PowerGUI but sysops tend to just use PowerShell to run them. Thus it worked on my dev box but failed in operations.

If you use PowerShell from the command line you need to add your membership config to: %windir%\System32\WindowsPowerShell\v1.0\PowerShell.exe.config
If you use the Windows PowerShell ISE then its: %windir%\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe.config
If you use PowerGUI then its: C:\Program Files (x86)\PowerGUI\PowerGUI.exe.config


Dec 31, 2014 at 6:51 AM

I am really struggling with this. Maybe I do not understand your reply.
I tried updating my powershell.exe.config with the connection string and membership stubs, as well as the full definitions added to the Dot.Net 4 machine.config file.
The user never gets added to the asp membership database using the new_spuser command in the same way it is listed by the OP. I have the same issue.

Are you asserting that if the Membership and Role provider config sections defining the FBA providers are properly added to the PowerShell config file that the command New-SPUser should add the user to the asp membership database in addition to defining the user in SharePoint?


Dec 31, 2014 at 6:52 AM
Edited Jan 26, 2015 at 11:22 PM
I just reviewed the source code and found that the code in NewuSer.aspx.cs calls the System,.Web.Security.MemberShip.CreateUser function.

So we need to code the addition of the user to the Membership database via System.Web.Security.MemberShip.CreateUser before calling new-spuser.

Jan 22, 2015 at 1:09 AM
HI asmhst

Are you able to share the powershell script. Much appreciated.

Thanks - Firoz Ozman
Jan 26, 2015 at 10:17 PM
Edited Jan 26, 2015 at 10:45 PM
My code is attached. It can always be improved (better error handling, etc). You add the user info to the Users.CSV file. Edit the welcome.html template for your specific situation. Edit the createUsersAndNotify.ps1 script to meet your needs. ________________________________________ Andy McKenna | IT Consultant
Jan 26, 2015 at 10:41 PM
Thank you so much Andy.
Attachment did not come thru. I guess you may need to rename it!
Please send it again.

Thanks again.