Mar 1, 2010

Manage ASP.NET Providers with PowerShell

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

24 comments:

rblitz said...

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

rblitz said...

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"

Christian said...

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

Web developer said...

Incredible points is found below using excellent content material, superb way with words-at all. I do not recognize how put it into practice but don’t stop! For those as if you occur on the internet.

Northfield Web Design said...

Let me test to see which language is to set up website.

Suhil H Jisaheb said...

Hello Christian,

I am facing same issue which rblitz has faced. My custom membership providers are not appearing in list.

What might be issue.

Can you plz help me out to resolve it.

Thanks Christian.

Anonymous said...

Same issue like the one of Suhil and rblitz.
And idea ?

rozina islam vabna said...

Thanks a bunch for sharing this with all people you actually recognize what you are talking about! Bookmarked. Kindly also discuss with my website.
Email list providers

Jameson Bozeman said...

After battling with getting my membership provider because the script didn't load my config path (resulting in "unable to connect to SQL Server database"). I found that once I ran this script from Windows Powershell (the blue one) everything worked. There must be some snapins in the SharePoint 2010 Management Shell that load other configs before the script can.

digital signature FAQ said...

Thank you so much for taking the time to share this information. A great read. I’ll certainly be back.

Chris said...

Regarding the "Unable to connect to SQL Server database" problem, this is because just changing the config file of current appdomain is not enough due to caching mechanisms in .NET -> you also need to "reset" the cache to force it to reload and take into account your new config file (more explanation here). You can do this in Powershell by using the following code (with help from here):

[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $appConfigPath )
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Web")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Configuration")

$BindingFlags= [Reflection.BindingFlags] "NonPublic,Static"

$PrivateField = [System.Configuration.ConfigurationManager].GetField("s_initState",$bindingFlags)
$PrivateField.SetValue($null, "NotStarted" -as [Int])

$PrivateField = [System.Configuration.ConfigurationManager].GetField("s_configSystem",$bindingFlags)
$PrivateField.SetValue($null, $null)

$c = [System.Configuration.ConfigurationManager].Assembly.GetTypes() | Where-Object {$_.FullName -eq "System.Configuration.ClientConfigPaths"}
$PrivateField = $c.GetField("s_current",$bindingFlags)
$PrivateField.SetValue($null, $null)

Cheap Chanel Bags said...

I honestly don’t find this bag pretty. Yes for sure it is a special piece as it’s one of the latest collaborations of the fashion house with select artists/ designers

Russell Wright said...

I also appreciate the work Christian has done, but am also facing the issues others have reported. I'm using the Windows PowerShell ISE and have been struggling with this all day. I finally made changes in the machine.config so it has the values I've been trying to read in the web.config to get it to work. I've now proved it will work, but I'm baffled as to why [System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $appConfigPath ) will not read the Membership Provider data in the web.config...it always falls back to the machine.config.

I guess I'll try it in the "non-ISE" environment to see if I get different results. I might also try what Chris recommended and try and reset the cache. Ugh!

Chris said...

Hi Russell,

I did have several problems also but forcing the cache to reload solved all these problems, give it a try !

Hug Day said...

happy hug day 2016 SMS
hug day 2016 Wishes cards greetings
Hug day Date 2016
hug day sms

风骚达哥 said...

20160423 junda
air jordans
cheap oakley sunglasses
kate spade outlet
adidas stan smith
ray ban sunglasses
michael kors outlet
nike air max shoes
cheap omega watches
yeezy boost 350
michael kors outlet online
michael kors outlet online
nike free runs
air jordan uk
michael kors outlet online
pandora charms
ray ban outlet
calvin klein outlet
fitflops sale clearance
toms outlet
nike huarache white
sac longchamp
toms outlet
michael kors outlet clearance
bottega veneta outlet
armani watches
gucci handbags
nike blazer
oakley sunglasses
true religion jeans
cheap jordans
ray bans
hollister
bottega veneta handbags
jimmy choo outlet
oakley sunglasses
converse
prada outlet
reebok shoes
true religion
burberry outlet

Libin Huang said...

20160426libinmichael kors outlet
cheap soccer jerseys
nike air max
ralph lauren uk
soccer jerseys wholesale
prada outlet online
cazal sunglasses
ralph lauren outlet
links of london
coach factory outlet
cheap nba jerseys
versace sunglasses
fitflops sale
michael kors outlet online
ralph lauren polo shirts
louis vuitton outlet online
kate spade handbags
coach handbags
michael kors handbags
ralph lauren uk
nhl jerseys
prada shoes
michael kors outlet store
hermes bags
michael kors uk
cheap nhl jerseys
ray ban sunglasses
lululemon outlet
cartier outlet
michael kors wallet
coach outlet online
true religion sale
louis vuitton handbags
lebron shoes
tiffany jewellery

محمد الخطيب said...



شركة كشف تسربات المياه بالاحساء
كشف تسربات المياه بالاحساء
شركة عزل اسطح بالاحساء
شركة عزل خزانات المياه بالاحساء
شركه عزل مائى بالاحساء
شركة عزل حرارى بالاحساء
شركة ترميم منازل بالاحساء
شركة مكافحة حشرات بالاحساء
شركة رش مبيدات بالاحساء
شركة تسليك مجارى بالاحساء
شركة ترميم منازل بالاحساء


Yuanyuan Lin said...

7.14lllllyuan"tiffany and co"
"michael kors outlet"
"hollister uk"
"michael kors outlet"
"salomon shoes sale"
"ralph lauren outlet"
"bottega veneta outlet online"
"fred perry polo"
"true religion jeans"
"michael kors outlet"
"camisetas futbol baratas"
"cartier outlet store"
"hollister"
"christian louboutin shoes"
"nike soccer shoes"
"polo ralph lauren"
"polo ralph lauren"
"michael kors outlet"
"longchamp handbags"
"fitflops sale"
"michael kors outlet"
"coach outlet online"
"louis vuitton handbags outlet"
"adidas shoes"
"tory burch shoes"
"chrome hearts eyewear"
"tory burch outlet"
"michael kors outlet"
"replica watches"
"burberry sunglasses on sale"
"louis vuitton bags"
"coach outlet"
"jordan shoes 2015"
"michael kors outlet"
"abercrombie outlet"
7.14

aboshady said...

شركة شراء اثاث مستعمل بالرياض
ارقام اثاث مستعمل بالرياض
محلات شراء الاثاث المستعمل بالرياض
محلات الاثاث المستعمل بالرياض

Fangyaya said...

michael kors purses
christian louboutin outlet
burberry handbags
coach outlet online
fitflop clearance
jordan 3s
michael kors
michael kors outlet
air jordan 8
replica rolex watches
adidas outlet store
michael kors outlet clearance
retro 11
cheap true religion jeans
cheap true religion
nike air max uk
replica rolex watches
christian louboutin shoes
supra footwear
louis vuitton bags
designer handbags
polo ralph lauren
cheap basketball shoes
adidas originals
coach outlet store online
coach outlet
cheap jordan shoes
oakley vault
jordan retro 4
coach factory outlet online
louis vuitton outlet
air jordan shoes
ed hardy outlet
gucci handbags
adidas yeezy
kobe shoes
discount jordans
cheap jordans
oakley sunglasses
coach factory outlet online
20168.8chenjinyan

محمد الخطيب said...


شركة كشف تسربات المياه بالرياض
كشف تسربات المياه بالرياض شركة كشف تسربات المياه بالدمام
كشف تسربات المياه بالدمام شركة كشف تسربات المياه بالاحساء
كشف تسربات المياه بالاحساء
شركة كشف تسربات المياه بالجبيل
كشف تسربات المياه بالجبيل
شركة كشف تسربات المياه بالخبر
كشف تسربات المياه بالخبر
شركة كشف تسربات المياه بالقصيم
كشف تسربات المياه بالقصيم
شركة كشف تسربات المياه بالقطيف
كشف تسربات المياه بالقطيف



كشف تسربات المياه بالظهران
شركة كشف تسربات المياه بالظهران
شركة عزل اسطح بالاحساء
شركة عزل اسطح بالظهران
شركة عزل اسطح براس تنوره
شركة عزل حراري براس تنوره
شركة تسليك مجارى براس تنوره
شركة كشف تسربات المياه بالنعيرية
شركة كشف تسربات المياه بسيهات
شركة كشف تسربات المياه براس تنورة
شركة مكافحة النمل الابيض بالدمام

dada24 Xu said...

cheap oakleys
ralph lauren pas cher
canada goose
michael kors outlet clearance
true religion outlet
armani exchange
gucci outlet
ed hardy
ugg boots
ray ban sunglasses
2016921caiyan

Paulo said...

Understudy advances for understudy with awful credit are the ideal answer for a credit issue. How about we investigate what kind of terrible credit understudy advance choices you have. Payday Loans San-diego