I’ve written this script to manage SQL users on a SharePoint box with form based security (FBA).
Usage:
Load the script
PS>. .\Manage_ASP_NET_Providers.ps1 “C:\..\web.config”
You have to provide the path to the web.config which contains the membership provider configurations.
The script will change the current app domain’s config path and then loads the System.Web Assembly. The sequence is important. If you want to change app config path later, you have to restart PowerShell and load the script again with another path.
Examples:
Get Membership Provider “sqlMembers”
PS> $provider = Get-MembershipProvider “sqlMembers”
Add a new user (login, mail, question, answer)
PS> $provider | Add-MembershipUser “cglessner” “cg@test.de” “Best Portal” “SharePoint”
List first 1000 users
PS> $provider | Get-MembershipUser –maxResult 1000
….
Bye, Christian
3 comments:
Christian,
I'm trying to use your PowerShell script (thanks for putting it together BTW.)
However, when I run it against a web.config file that I know is configured properly for a SharePoint web app that's using SqlMembershipProvider for FBA, I get "Unable to connect to SQL Server database". I know that the data connection is valid because FBA is otherwise working.
I think that it's finding an inherited provider, but not the configured provider.
Any hints?
Thanks
Followup to my previous query: it appears that the script can't find my provider by name. If I don't supply a name, it finds one called "AspNetSqlMembershipProvider"
Hi, it seems the script will fallback to the machine config. To read the web.config settings I switch the config file of the app domain. This just works if Shell hasn't read any config value before. Please check that you use the script in a fresh shell instance without any snapins that you don't need.
Bye, Christian
Post a Comment