PoshCode Logo PowerShell Code Repository

Manage ASP.NET Providers by cglessner 23 months ago
View followups from cglessner and cglessner | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1668"></script>download | new post

Manage ASP.NET MemberShip, Role and Profile Provider with PowerShell. Especially useful with SqlMembershipProvider. I use it to manage SharePoint users with form based authentication (FBA).

  1. # Manage_ASP_NET_Providers.ps1
  2. # by Chistian Glessner
  3. # http://iLoveSharePoint.com
  4.  
  5. [void][System.Reflection.Assembly]::LoadWithPartialName("System.Web") # posh 2.0: Add-Type -Assembly "System.Web"
  6.  
  7. function global:Set-AppConfigPath($path=$(throw "-path is mandatory"))
  8. {
  9.     [System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $path )
  10. }
  11.  
  12. function global:Get-MembershipProvider($appConfigPath=$null, $providerName=$null)
  13. {
  14.     if($appConfigPath -ne $null)
  15.     {
  16.         Set-WebConfigPath $webConfigPath
  17.     }
  18.    
  19.     if($providerName -eq $null)
  20.     {
  21.         return [System.Web.Security.Membership]::Provider
  22.     }
  23.     else
  24.     {
  25.         return [System.Web.Security.Membership]::Providers[$providerName]
  26.     }
  27.    
  28. }
  29.  
  30. function global:Get-RoleProvider($appConfigPath=$null, $providerName=$null)
  31. {    
  32.     if($appConfigPath -ne $null)
  33.     {
  34.         Set-WebConfigPath $webConfigPath
  35.     }
  36.  
  37.     if($providerName -eq $null)
  38.     {
  39.         return [System.Web.Security.Roles]::Provider
  40.     }
  41.     else
  42.     {
  43.         return [System.Web.Security.Roles]::Providers[$providerName]
  44.     }
  45. }
  46.  
  47. function global:Get-ProfileProvider($appConfigPath=$null, $providerName=$null)
  48. {    
  49.     if($appConfigPath -ne $null)
  50.     {
  51.         Set-WebConfigPath $webConfigPath
  52.     }
  53.  
  54.     if($providerName -eq $null)
  55.     {
  56.         return [System.Web.Profile.ProfileManager]::Provider
  57.     }
  58.     else
  59.     {
  60.         return [System.Web.Profile.ProfileManager]::Providers[$providerName]
  61.     }
  62. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me